Originally Posted by
Roasted
Is there any way we can break down that grep command so I understand it easier?
The first part, cat /proc/mounts, is a list of currently mounted filesystems - you could equally use the mount command. The output is piped into grep to search for a particular mountpoint.
Note that your second mount at /mount/storage would also match your third at /mount/storagebackup, so add the -w (whole word) option to grep.
The variable $? is (I think) a success flag. Whatever it is, echo $? shows you 0 if a command returned a result, or 1 if it did not - most commands return 0. Grep returns 0 if the string was matched and 1 if it was not.
So we just check each mountpoint in turn and run rsync if it is present.
Code:
cat /proc/mounts | grep -w /media/localbackup
if [ $? -eq 0 ] ; then
rsync -a --progress --delete source1 /media/localbackup
fi
cat /proc/mounts | grep -w /media/storage
if [ $? -eq 0 ] ; then
rsync -a --progress --delete source2 /media/storage
fi
cat /proc/mounts | grep -w /media/storagebackup
if [ $? -eq 0 ] ; then
rsync -a --progress --delete source3 /media/storagebackup
fi
I have my backup script on the desktop to click whenever I want to feel like I have done something important. I could add it to crontab, but that would be too organized.
Bookmarks