Chris
2018-Sep-11 16:28 UTC
Ensuring that rsync doesn't try to write to an unmounted drive
I have a script that runs nightly as a cronjob to backup my drive to a USB drive https://pastebin.com/yivqrGUC On the command line I use the --timeout option. Is this sufficient to ensure that if the external drive somehow becomes unmounted that rsync will gracefully fail without trying to write to the hard drive instead of the USB drive? rsync -vaWSHpl --timeout=15 --delete-excluded --filter "merge ${EXC_FILE}" / "${BACKUP_DIR}" > /home/chris/rsyncbackup.log 2> /home/chris/rsyncbackup.errors.log If this is sufficient or would it be better if I lowered the 'timeout' to 5 seconds? Thanks for any suggestions/advice. Chris -- Chris KeyID 0xE372A7DA98E6705C 31.11972; -97.90167 (Elev. 1092 ft) 11:18:25 up 18:25, 1 user, load average: 1.18, 1.41, 1.43 Description: Ubuntu 18.04.1 LTS, kernel 4.15.0-34-generic -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part URL: <http://lists.samba.org/pipermail/rsync/attachments/20180911/7d726142/signature.sig>
Kevin Korb
2018-Sep-11 16:56 UTC
Ensuring that rsync doesn't try to write to an unmounted drive
--timeout is about network connection timeouts. You aren't using the network so it doesn't apply at all. Even if you were networking an unmounted filesystem is an empty directory as far as rsync is concerned and rsync would treat it that way with no idea that you intended to have something mounted there. Now, I see at the top of your script you check for the existence of the target directory. If that isn't the root of a filesystem then you are good because you are already checking for that. If it is the root of the filesystem then it will exist either as an empty directory or a mount point and you need to check for those possibilities. On 09/11/2018 12:28 PM, Chris via rsync wrote:> I have a script that runs nightly as a cronjob to backup my drive to a > USB drive https://pastebin.com/yivqrGUC On the command line I use the > --timeout option. Is this sufficient to ensure that if the external > drive somehow becomes unmounted that rsync will gracefully fail without > trying to write to the hard drive instead of the USB drive? > > rsync -vaWSHpl --timeout=15 --delete-excluded --filter "merge > ${EXC_FILE}" / "${BACKUP_DIR}" > /home/chris/rsyncbackup.log 2> > /home/chris/rsyncbackup.errors.log > > If this is sufficient or would it be better if I lowered the 'timeout' > to 5 seconds? > > Thanks for any suggestions/advice. > > Chris > > >-- ~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._., Kevin Korb Phone: (407) 252-6853 Systems Administrator Internet: FutureQuest, Inc. Kevin at FutureQuest.net (work) Orlando, Florida kmk at sanitarium.net (personal) Web page: https://sanitarium.net/ PGP public key available on web site. ~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._., -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 195 bytes Desc: OpenPGP digital signature URL: <http://lists.samba.org/pipermail/rsync/attachments/20180911/86579776/signature.sig>
Chris
2018-Sep-11 18:06 UTC
Ensuring that rsync doesn't try to write to an unmounted drive
On Tue, 2018-09-11 at 12:56 -0400, Kevin Korb via rsync wrote:> --timeout is about network connection timeouts. You aren't using the > network so it doesn't apply at all. Even if you were networking an > unmounted filesystem is an empty directory as far as rsync is > concerned > and rsync would treat it that way with no idea that you intended to > have > something mounted there.Thanks Kevin, didn't realize that. Missed that when reading about -- timeout.> > Now, I see at the top of your script you check for the existence of > the > target directory. If that isn't the root of a filesystem then you > are > good because you are already checking for that. If it is the root of > the filesystem then it will exist either as an empty directory or a > mount point and you need to check for those possibilities.I hope I'm answering your question. The mount info on the drive is /dev/sdb1 on /media/chris/backup2 type ext4 (rw,nosuid,nodev,relatime,data=ordered,uhelper=udisks2) However, in the script it's actually checking for the folder the backup is written to 'snapshot' BACKUP_DIR="/media/chris/backup2/snapshot/" if [ ! -d ${BACKUP_DIR} ];then echo "Backup destination directory ${BACKUP_DIR} not exist." echo "run 'sudo mkdir ${BACKUP_DIR}' to create. " exit 1 So if I understand the script is checking for the 'snapshot' folder on the mount point 'backup2'. Is that correct? If rsync can't see the 'snapshot' folder would it still turn around and write or attempt to write the backup to the hard drive or would it gracefully fail? I had asked a question on LQ.org about the script earlier because I couldn't see why it wasn't making a log file. Note-this script was written by someone here on the list for me about 4 or so years ago. Yes, it took me that long to notice. One of the replies to my question suggested that I add this to the script: mount_point='/media/chris/backup2' df -h | grep $mount_point > /dev/null if [ $? -eq 0 ] then rsync......... echo "mount point $mount_point exists, rsync started" else echo "Error: mount point $mount_point does not exist, rsync operation skipped" So, would it be ok to leave it as is or do I need to add the above to check for the actual mount point?> > On 09/11/2018 12:28 PM, Chris via rsync wrote: > > I have a script that runs nightly as a cronjob to backup my drive > > to a > > USB drive https://pastebin.com/yivqrGUC On the command line I use > > the > > --timeout option. Is this sufficient to ensure that if the external > > drive somehow becomes unmounted that rsync will gracefully fail > > without > > trying to write to the hard drive instead of the USB drive? > > > > rsync -vaWSHpl --timeout=15 --delete-excluded --filter "merge > > ${EXC_FILE}" / "${BACKUP_DIR}" > /home/chris/rsyncbackup.log 2> > > /home/chris/rsyncbackup.errors.log > > > > If this is sufficient or would it be better if I lowered the > > 'timeout' > > to 5 seconds? > > > > Thanks for any suggestions/advice. > > > > Chris > > > > > > > >-- Chris KeyID 0xE372A7DA98E6705C 31.11972; -97.90167 (Elev. 1092 ft) 12:50:18 up 19:57, 1 user, load average: 0.82, 0.92, 1.29 Description: Ubuntu 18.04.1 LTS, kernel 4.15.0-34-generic -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part URL: <http://lists.samba.org/pipermail/rsync/attachments/20180911/0fad40d5/signature.sig>