mirror of
https://github.com/Facundo-prog/automatic_backup_script.git
synced 2025-10-14 00:59:40 +00:00
Update backup-files.sh
Se mejoró lo siguiente: - se añadió "set -euo pipefail" para asegurar que el script falle en cuanto algo no funcione - se creara un registro log en /var/log/backup.log - se utiliza el UUID en el mount del disco para evitar errores de montaje - se agrego "mkdir -p" en la creación de carpetas para evita problemas si faltan directorios padres. - se añadió umount -l "$backup_path" para evitar errores si el disco está ocupado
This commit is contained in:
parent
056a17904f
commit
23eae0ad55
@ -1,11 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Errors checker
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Save log
|
||||||
|
exec > >(tee -a /var/log/backup.log) 2>&1
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
# Unmount disk after save backup
|
# Unmount disk after save backup
|
||||||
unmount_disk=true
|
unmount_disk=true
|
||||||
|
|
||||||
# Disk backup mount point
|
# Disk backup mount point
|
||||||
backup_path="/backup-disk"
|
backup_path="/backup-disk"
|
||||||
|
disk_UUID="aba6bd5-a5sd5b51d-adsfb4542"
|
||||||
|
|
||||||
# Origins files array
|
# Origins files array
|
||||||
origins=("/home/facu/Documents/backup_folder")
|
origins=("/home/facu/Documents/backup_folder")
|
||||||
@ -26,22 +33,14 @@ perform_backup() {
|
|||||||
|
|
||||||
# The destination folder not exists
|
# The destination folder not exists
|
||||||
if [ ! -d "$destination" ]; then
|
if [ ! -d "$destination" ]; then
|
||||||
echo "Folder $destination created"
|
echo "Creating folder $destination"
|
||||||
mkdir "$destination"
|
mkdir -p "$destination"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute rsync
|
# Execute rsync
|
||||||
|
echo "Starting backup $origin -> $destination"
|
||||||
rsync -av --delete "$origin/" "$destination/"
|
rsync -av --delete "$origin/" "$destination/"
|
||||||
|
echo "Backup successfully saved $origin on $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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -53,13 +52,13 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# Mount disk
|
# Mount disk
|
||||||
mount "$backup_path"
|
|
||||||
echo "Mounting disk..."
|
echo "Mounting disk..."
|
||||||
|
mount UUID="$disk_UUID" "$backup_path"
|
||||||
|
|
||||||
|
|
||||||
# The disk not mount
|
# The disk not mount
|
||||||
if ! mountpoint -q "$backup_path"; then
|
if ! mountpoint -q "$backup_path"; then
|
||||||
echo "Error occurred when mounting disk"
|
echo "Error occurred when mounting disk. Aborting..."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -74,6 +73,6 @@ done
|
|||||||
if [ "$unmount_disk" = true ]; then
|
if [ "$unmount_disk" = true ]; then
|
||||||
if mountpoint -q "$backup_path"; then
|
if mountpoint -q "$backup_path"; then
|
||||||
echo "Unmounting disk..."
|
echo "Unmounting disk..."
|
||||||
umount "$backup_path"
|
umount -l "$backup_path"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user