Sync directories using bash

I use rsync command to sync some local directories to my external HDD. I wrote a simple bash script to do this job. I’d set up a reminder service to get notification on weekly basis. On getting that reminder, I just run this bash script to synchronize files.

Some advantages and features of rsync command-

1. It efficiently copies and sync files to or from a remote system.
2. Supports copying links, devices, owners, groups and permissions.
3. It’s faster than scp because it uses remote-update protocol which allows to transfer just the differences between two sets of directories. First time, it copies the whole content of a directory from source to destination but from next time, it copies only the changed blocks and bytes to the destination.

Here is its basic implementation

#!/bin/bash

#sync docs, delete files that are not there in source directory
rsync -rzvhW --delete /home/kuntal/Documents/ /media/FreeAgent\ GoFlex\ Drive/My\ Data/Docs/

#sync photos
rsync -rzvhW /home/kuntal/Pictures/ /media/FreeAgent\ GoFlex\ Drive/My\ Data/Photos/

#sync study materials, delete files that are not there in source directory
rsync -rzvhW --delete /home/kuntal/Study\ Materials/ /media/FreeAgent\ GoFlex\ Drive/My\ Data/Study\ Materials/

#sync movies
rsync -rzvhW /home/kuntal/Videos/ /media/FreeAgent\ GoFlex\ Drive/My\ Data/Movies/

That’s all to sync all of my required data.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s