Hi,
I'm trying to automate a backup of various directories using Rsync. The source directories are mounts of a couple of network shares & the destination is the mount of an external USB drive.
I have an issue with one of the directories where my script reports that the destination doesn't exist when I'm checking to see if it exists or not & I believe this is because the folder contains subfolders but no files (the subfolders contain files though).
I'm also concerned that using the --delete parameter for Rsync could effectively remove all files in the backup if the source is not mounted for some reason. The script does check if the folder exists, but if it's not mounted the folder would still exist meaning there are no files & Rsync may believe the files have been deleted & remove the files in the destination. How should I prevent this from occuring?
I would apreciate any help / advice.
I'm trying to automate a backup of various directories using Rsync. The source directories are mounts of a couple of network shares & the destination is the mount of an external USB drive.
I have an issue with one of the directories where my script reports that the destination doesn't exist when I'm checking to see if it exists or not & I believe this is because the folder contains subfolders but no files (the subfolders contain files though).
I'm also concerned that using the --delete parameter for Rsync could effectively remove all files in the backup if the source is not mounted for some reason. The script does check if the folder exists, but if it's not mounted the folder would still exist meaning there are no files & Rsync may believe the files have been deleted & remove the files in the destination. How should I prevent this from occuring?
I would apreciate any help / advice.
Code:
#!/bin/bash
src='/home/craig'
dest='/media/Backup'
sourcedirs=( 'Music' 'wii' 'Pictures' 'my_stuff' )
destdirs=( 'mp3s' 'wii' 'my_pics' 'my_stuff' )
sourceelements=${#sourcedirs[@]}
destelements=${#destdirs[@]}
if [ "$sourceelements" -ne "$destelements" ];
then
echo "The number of Source & Destination directories differ\nSource = $sourceelements Destination = $destelements"
else
for (( i=0;i<$sourceelements;i++)); do
if [ -d "$src/${sourcedirs[${i}]}" ] && [ -d "$dest/${destdirs[${i}]}" ];
then
echo "syncing files from $src/${sourcedirs[${i}]}/ to $dest/${destdirs[${i}]}/"
#rsync -arv --progress --delete --log-file=$src/$(date +%Y%m%d)_rsync.log $src/${sourcedirs[${i}]}/ $dest/${destdirs[${i}]}/
else
if [ -d "$src/${sourcedirs[${i}]}" ];
then
echo "Source folder $src/${sourcedirs[${i}]}/ not found"
else
echo "Destination folder $dest/${destdirs[${i}]}/ not found"
fi
fi
done
fi