Monday, January 14, 2013

Using rsync to keep my media files current.


I've been using rsync to keep my media folder current between my server and an external drive. The server is an ext4 partition and the remote drive is formatted as NTFS for compatibility reasons.

I've written a little bash script to make this fool proof. One option to sync to my media server and one option to sync to my desktop where the external drive gets mounted.

The media server is mounted via CIFS to my workstation as /storage/media/Movies

The external drive is mounted NTFS-3g as /external/Movies

#! /bin/bash
PS3='Please enter your choice: '
options=("Sync to Server" "Sync to Desktop"  "Quit")
select opt in "${options[@]}"
    case $opt in
        "Sync to Server")
            echo "you chose Sync to Server";
            rsync -rltDvu --modify-window=1 --progress /external/Movies/ /storage/media/Movies/;
        "Sync to Desktop")
            echo "you chose Sync to Desktop";
            rsync -rltDvu --modify-window=1 --progress /storage/media/Movies/ /external/Movies/;
        *) echo invalid option;;

This script give me 2 options. 1 Syncs from the external drive to my server and 2 syncs from the server to the external drive.

I'm no bash wizard but if this helps you great!