Rsync - Backup specific files & folders to specific drives

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
vanhoopstallion

Rsync - Backup specific files & folders to specific drives

Post by vanhoopstallion »

hello,

I use Rsync to transfer my downloads onto a NAS drive once complete via the crontab. I'd like to make crontab transfer specific music and video files with their folders to the corresponding video or music folder on the NAS. The code below works well if only the *.mkv included file exists in the folder, if it's mixed then it wont transfer.

thanks

Code: Select all

rsync -a --include='*.mkv' --exclude='*' --include='*/' /home/name/downloads/ /MyNas/video/
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
WharfRat

Re: Rsync - Backup specific files & folders to specific driv

Post by WharfRat »

Your includes and excludes are confusing - they shouldn't be needed.

If there are other file types in /home/name/downloads/ then just exclude those types in a brace expansion e.g. --exclude={torrents,.cache,.mozilla*,.googleearth}

You can test the line using the -n option or leaving off the destination in which case the output will go to the terminal.

Good luck :wink:
mintybits

Re: Rsync - Backup specific files & folders to specific driv

Post by mintybits »

Is it that you have folders and files with the same root name and you want to copy all to /myNAS/Video?
Eg:

Code: Select all

Abba the movie.mkv
Abba the movie/
    castlist
    other-stuff
A way to do this might be:

Code: Select all

cd Downloads
ls *.mkv | rev | cut -d "." -f2- | rev | while read line; do echo "$line.mkv" | rsync -va --files-from=- . /myNAS/video/ ; rsync -va "$line" /myNAS/video/; done
UltramaticOrange

Re: Rsync - Backup specific files & folders to specific driv

Post by UltramaticOrange »

And for the casual reader not already familiar with rsync, you should know that it is VERY handy for securely copying files between systems as well.

Code: Select all

rsync -rave "ssh" /home/$(whoami) myOtherUser@myOtherComputer:/mnt/backups
Strictly speaking, -e and "ssh" shouldn't be needed here, but handy if you want to specify an external SSH key.
Locked

Return to “Scripts & Bash”