mirror of
https://github.com/Facundo-prog/automatic_backup_script.git
synced 2025-07-06 19:12:28 +00:00
updated
This commit is contained in:
parent
3beb764ad2
commit
4f4092e92d
95
README.md
Normal file
95
README.md
Normal file
@ -0,0 +1,95 @@
|
||||
# Automatic backup files script
|
||||
|
||||
## Prerquisites
|
||||
|
||||
* Rsync (included in Debian, Ubuntu, Linux Mint, etc)
|
||||
* Sudo or Root access
|
||||
* Terminal learn
|
||||
|
||||
## Quick start
|
||||
|
||||
|
||||
1- If disk on save backup is diferent a instalation disk:
|
||||
|
||||
Copy UUID your disk
|
||||
|
||||
sudo blkid
|
||||
|
||||
Editing disks mount points file
|
||||
|
||||
sudo nano /etc/fstab
|
||||
|
||||
Replace backup external disk UUID and mount point for you configuration
|
||||
```
|
||||
# /etc/fstab: static file system information.
|
||||
#
|
||||
# Use 'blkid' to print the universally unique identifier for a
|
||||
# device; this may be used with UUID= as a more robust way to name devices
|
||||
# that works even if disks are added and removed. See fstab(5).
|
||||
#
|
||||
# systemd generates mount units based on this file, see systemd.mount(5).
|
||||
# Please run 'systemctl daemon-reload' after making changes here.
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
|
||||
# Others discks
|
||||
UUID= /boot/efi vfat umask=0077 0 1
|
||||
|
||||
# backup external disk
|
||||
UUID=645648-kadfvadfb86teyn1sd3 /backup-disk ext4 defaults 0 0
|
||||
```
|
||||
|
||||
1- Modify custom service:
|
||||
|
||||
* Default backup run on 1 hour (RestartSec=3600)
|
||||
* Default bash script path is "/home/backup-files.sh" (ExecStart=/to/bash/file)
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Automatic backup files
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
ExecStart=/home/backup-files.sh
|
||||
Restart=always
|
||||
RestartSec=3600
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
2- Copy service into path /etc/systemd/system/
|
||||
|
||||
sudo cp backup-files.service /etc/systemd/system/
|
||||
|
||||
sudo systemctl dameon-reload
|
||||
|
||||
sudo systemctl enable backup-files.service
|
||||
|
||||
|
||||
3- Modify script
|
||||
|
||||
```
|
||||
# Paths
|
||||
external_disk=true // Default backup saved on external disk
|
||||
backup_path="/backup-disk" //Disk backup mount point
|
||||
origins=("/home/user1/files" "/home/user2/files/documents") // Origins files array
|
||||
destinations=("$backup_path/backup-user1" "$backup_path/backup-user2") // Destination backups
|
||||
```
|
||||
|
||||
4- Copy script into ExecStart= path defined in .service
|
||||
|
||||
sudo cp backup-files.sh /home/
|
||||
|
||||
|
||||
5- Test script commands
|
||||
|
||||
sudo bash /home/backup-files.sh
|
||||
|
||||
6- If before Test not return never error, then start sevice
|
||||
|
||||
sudo systemctl start backup-files.service
|
||||
|
||||
sudo systemctl status backup-files.service
|
@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Paths
|
||||
external_disk=true
|
||||
backup_path="/backup-disk"
|
||||
origins=("/home/user1/files" "/home/user2/files/documents")
|
||||
destinations=("$backup_path/backup-user1" "$backup_path/backup-user2")
|
||||
@ -16,6 +17,8 @@ perform_backup() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ external_disk ]; then
|
||||
|
||||
# The mount point disk not exists
|
||||
if [ ! -d "$backup_path" ]; then
|
||||
mkdir -p "$backup_path"
|
||||
@ -27,6 +30,8 @@ perform_backup() {
|
||||
echo "Mounting disk..."
|
||||
mount "$backup_path"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# The destination folder not exists
|
||||
if [ ! -d "$destination" ]; then
|
||||
@ -53,8 +58,11 @@ for (( i=0; i<${#origins[@]}; i++ )); do
|
||||
perform_backup "${origins[i]}" "${destinations[i]}"
|
||||
done
|
||||
|
||||
# Umount disk
|
||||
if mountpoint -q "$backup_path"; then
|
||||
|
||||
if [ external_disk ]; then
|
||||
# Umount disk
|
||||
if mountpoint -q "$backup_path"; then
|
||||
echo "Umounting disk..."
|
||||
umount "$backup_path"
|
||||
fi
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user