Saturday, July 12, 2008

Using rsync to keep desktop and server music files in sync

It's not perfect, but I've come up with a pretty good way to keep my music folder clean, and in sync with my server. This way, I can put files in the music folder on either the server or on my Desktop, and I don't have to worry about which files are where. It makes sure its the same on both.

My script also deletes the typical files you get when you're downloading music files, like text, urls, jpg's, etc.

I have a samba share permanently mounted on my desktop, so I can work on the server files as if they're local.

So, here's the script.

# Delete all the crap files on desktop before syncing
find /home/username/Music/ -regextype posix-awk -regex "(.*.jpg|.*.ini|.*.rtf|.*.url|.*.txt|.*.log|.*.sfv|.*.nfo|
.*.md5|.*.m3u)" -exec rm -v {} \;

# Delete all the crap files on server before syncing
find /home/username/servername/music -regextype posix-awk -regex "(.*.jpg|.*.ini|.*.rtf|.*.url|.*.txt|.*.log|.*.sfv|.*.nfo|
.*.md5|.*.m3u)" -exec rm -v {} \;

#sync music from desktop to server
rsync -r -t -v --progress /home/username/Music/ /home/username/servername/music/

#sync music from server to desktop
rsync -r -t -v --progress /home/username/servername/music/ /home/username/Music/


That's all there is to it. This will only synchronize new files that you put on there. It won't delete any files, unless they're of the file types specified above. You can change it to suit your needs.

You could even set this up in a cron job and have it syncing daily.

3 comments:

Anonymous said...

Just found your post via Digg. It will come in very handy for myself, many thanks!

Ryan said...

Did you look into Unison for this? I use it because it transfers files both ways.

Happy Linux Guy said...

rsync can transfer files both ways too, but the option I used limited it to one way on purpose.