mirror of
https://github.com/Facundo-prog/automatic_backup_script.git
synced 2025-03-30 14:48:27 +00:00
create repository
This commit is contained in:
parent
ab33d836de
commit
3beb764ad2
13
backup-files.service
Normal file
13
backup-files.service
Normal file
@ -0,0 +1,13 @@
|
||||
[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
|
60
backup-files.sh
Normal file
60
backup-files.sh
Normal file
@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Paths
|
||||
backup_path="/backup-disk"
|
||||
origins=("/home/user1/files" "/home/user2/files/documents")
|
||||
destinations=("$backup_path/backup-user1" "$backup_path/backup-user2")
|
||||
|
||||
# Function to perform backup for each origin-destination pair
|
||||
perform_backup() {
|
||||
local origin="$1"
|
||||
local destination="$2"
|
||||
|
||||
# The origin folder not exists
|
||||
if [ ! -d "$origin" ]; then
|
||||
echo "Origin folder not exists: $origin"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# The mount point disk not exists
|
||||
if [ ! -d "$backup_path" ]; then
|
||||
mkdir -p "$backup_path"
|
||||
echo "Mount point disk created"
|
||||
fi
|
||||
|
||||
# The disk not mount
|
||||
if ! mountpoint -q "$backup_path"; then
|
||||
echo "Mounting disk..."
|
||||
mount "$backup_path"
|
||||
fi
|
||||
|
||||
# The destination folder not exists
|
||||
if [ ! -d "$destination" ]; then
|
||||
echo "Folder $destination created"
|
||||
mkdir "$destination"
|
||||
fi
|
||||
|
||||
# Execute rsync
|
||||
rsync -av --delete "$origin/" "$destination/"
|
||||
|
||||
# Verify folder backup
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Backup successfully saved $origin on $destination"
|
||||
else
|
||||
echo "Error on copy files"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Iterate over origin-destination pairs and perform backup
|
||||
for (( i=0; i<${#origins[@]}; i++ )); do
|
||||
perform_backup "${origins[i]}" "${destinations[i]}"
|
||||
done
|
||||
|
||||
# Umount disk
|
||||
if mountpoint -q "$backup_path"; then
|
||||
echo "Umounting disk..."
|
||||
umount "$backup_path"
|
||||
fi
|
16
fstab
Normal file
16
fstab
Normal file
@ -0,0 +1,16 @@
|
||||
# /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= /backup-disk ext4 defaults 0 0
|
Loading…
x
Reference in New Issue
Block a user