Sun 10 Feb 2008
Using Rsync for syncing “My Pictures” and other directories (DFS)
Posted by Steve under Linux , TechnologyNo Comments
We recently had a baby and take a LOT of pictures. The problem is, depending on which way the stars are aligned, my wife or I will:
- Download pictures with the USB cable provided to her laptop
- Place SD card into the printer of her computer and grab them that way
- Or I will place the SD card into the SD card reader on my PC and grab them
The problem with this is, the pictures are scattered about over 3 machines and I never know where they are. Its was getting increasingly annoying, so I decided to sync the “My Pictures” folder on each of our three windows machines with Rsync, mount, and cron on my Fedora machine. The main idea is to Pull all three “My Pictures” folders to the linux in one central folder. And then push that central folder back out to all three machines.
Step 1:
Mount your windows machine to /mnt/directory
mount -t cifs //192.168.1.2/C$ -o username=USERNAME,password=PASSWORD /mnt/Windows_C/.
Step 2:
use Rsync to grab directory listing and grab only updated or new items.
rsync -aruvz /mnt/Windows_C/Documents\ and\ Settings/steve/My\ Documents/My\ Pictures/Addison/* /home/sbak/AddisonSync/.
Step 3:
Repeat steps 1 and 2 for all machines that you wish to sync.
Step 4:
Push the sync’d folder on the linux machine to all machines that need to be synced. To do this, you simply reverse the source and destination fields of the rsync command in step 2.
rsync -aruvz /home/sbak/AddisonSync/* /mnt/Windows_C/Documents\ and\ Settings/steve/My\ Documents/My\ Pictures/Addison/.
Step 5:
Put the above steps into a shell script. One for pull and one for push for each machine.
PullMachineA.sh:
mount -t cifs //192.168.1.2/C$ -o username=USERNAME,password=PASSWORD /mnt/Windows_C/.
rsync -aruvz /mnt/Windows_C/Documents\ and\ Settings/steve/My\ Documents/My\ Pictures/Addison/* /home/sbak/AddisonSync/.
umount /mnt/Windows_C/
PushMachineB.sh
mount -t cifs //192.168.1.2/C$ -o username=USERNAME,password=PASSWORD /mnt/Windows_C/.
rsync -aruvz /home/sbak/AddisonSync/* /mnt/Windows_C/Documents\ and\ Settings/steve/My\ Documents/My\ Pictures/Addison/.
umount /mnt/Windows_C/
Step 6:
schedule shell scripts in crontab. I scheduled mine every 6 hours.
0 0,6,12,18 * * * (/home/sbak/Syncs/pullA.sh >> /home/sbak/Syncs/logs/AddisonSync.log)
10 0,6,12,18 * * * (/home/sbak/Syncs/pullB.sh >> /home/sbak/Syncs/logs/AddisonSync.log)
20 0,6,12,18 * * * (/home/sbak/Syncs/pullC.sh >> /home/sbak/Syncs/logs/AddisonSync.log)
30 0,6,12,18 * * * (/home/sbak/Syncs/pushA.sh >> /home/sbak/Syncs/logs/AddisonSync.log)
40 0,6,12,18 * * * (/home/sbak/Syncs/pushB.sh >> /home/sbak/Syncs/logs/AddisonSync.log)
50 0,6,12,18 * * * (/home/sbak/Syncs/pushC.sh >> /home/sbak/Syncs/logs/AddisonSync.log)