I have the following script using rsync
for backuping and synchronization of my files.
How can I make this script more compact, faster and with better error handling?
#!/bin/sh
errors=""
sudo rsync -avh --delete --no-o --no-g /home/xralf/audio /media/extdevice/rsync_backups/
if [ "$?" -eq "0" ]
then
echo "no errors in audio"
else
errors="${errors}error in audio\n"
fi
sudo rsync -avh --delete --no-o --no-g /home/xralf/books /media/extdevice/rsync_backups/
if [ "$?" -eq "0" ]
then
echo "no errors in books"
else
errors="${errors}error in books\n"
fi
sudo rsync -avh --delete --no-o --no-g /home/xralf/source_code /media/extdevice/rsync_backups/
if [ "$?" -eq "0" ]
then
echo "no errors in source_code"
else
errors="${errors}error in source_code\n"
fi
# more such directories with this code pattern
echo ${errors}
Later I plan not to watch the script execution, so I'd like to see only the result and believe everything went right.
I ran the script, but in the end, the only information I have is error in source_code
, and I can't see, what exactly the error is (which file caused it).
sh
or can you usebash
?