[PLUG] Rsync again

Larry Brigman larry.brigman at gmail.com
Sun Oct 7 01:22:20 UTC 2018


I would add checking of the return code (exit code) for the 'cd' commands.
As it is now those could fail but something latter would have to detect the
failure.

On Sat, Oct 6, 2018, 5:28 PM John Jason Jordan <johnxj at gmx.com> wrote:

> On Sat, 06 Oct 2018 13:08:21 -0700
> Tomas K <tomas.kuchta.lists at gmail.com> dijo:
>
> >Simple if statement in your backup script should take care of it.
> >You can do it number of ways - here is one - checking that there is any
> >content in the directory before starting rsync (in bash):
> >
> >#!/bin/bash
> >backupTargetDir=/media/jjj/Synology
> >cd $backupTargetDir
> ># wait 30 seconds for the directory to mount
> >sleep 30
> >filesInDir=$(ls | wc -l)
> >if (( $filesInDir > 0 )); then
> >  echo "INFO: Backing up files to $backupTargetDir"
> >  rsync ....
> >else
> >  echo "WARNING: No files in $backupTargetDir"
> >fi
>
> ¡Me gusta!
>
> Here is how I finalized it:
>
> #!/bin/bash
> cd ..
> cd /media/jjj/Movies
> backupTargetDir=/media/jjj/Synology
> cd $backupTargetDir
> # wait 30 seconds for the directory to mount
> sleep 30
> filesInDir=$(ls | wc -l)
> if (( $filesInDir > 0 )); then
>   echo "INFO: Backing up files to $backupTargetDir"
>   rsync -rptog --progress --stats --delete
> --exclude-from=/media/jjj/Movies/rsync_exclusions /media/jjj/Movies/
> /media/jjj/Synology
> else echo "WARNING: No files in $backupTargetDir"
> fi
>
> I could probably add another if statement to be sure
> that /media/JJJ/Movies is mounted, but that's my work directory, so
> it's highly unlikely that it would not be mounted.
>
> I tested it and it works fine! Thanks for the help!
> _______________________________________________
> PLUG mailing list
> PLUG at pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list