Activities

June 2011
M T W T F S S
« Apr   Jul »
 12345
6789101112
13141516171819
20212223242526
27282930  

How do I exclude certain files/folders from rsync

It’s a long time after starting blogging. I found one interesting option in “rsysnc” where we can skip specified files from being synchronized. This mechansim would be helpful if you have many web server cluster configured for a site.

while I’m setting up Elastic load balancer in Amazon, I need to keep all the production node to be updated frequently where users has ftp access to only on Maser node.

1. If you want to exclude a folder from being synchronized you may add the parameter “–exclude in the rsync usage.

Source : 10.13.7.122:/home/mydomain/public_html/
Destination : /home/mydomain/public_html/
Connectivity : ssh
Excluded folder : uploads

/usr/bin/rsync --delete -avz --exclude uploads -e ssh 10.13.7.122:/home/mydomain/public_html/   /home/mydomain/public_html/

2. If you want to exclude certain files, you may add “–exclude ‘filename’

Eg:

/usr/bin/rsync --delete -avz --exclude 'wordpress/wp-config.php'  -e ssh 10.13.7.122:/home/mydomain/public_html/   /home/mydomain/public_html/

This may helpfull if you don’t want to duplicate the locally created cache file likes logs, scripts created at runtime and database config. files.

Example of cross usage,

/usr/bin/rsync --delete -avz --exclude uploads --exclude resources  --exclude 'wordpress/wp-config.php' --exclude 'system/application/config/database.php'  --exclude js/parsed/ --exclude style/parsed/ --exclude system/cache/ --exclude system/logs/ -e ssh 10.13.7.122:/home/mydomain/public_html/   /home/mydomain/public_html/

Pls note that I have added it on the cronjob and ssh auto login to each node is enabled from the master node

3. If you customized the ssh port on source server, you may use the port parameter in rsync

Eg:

/usr/bin/rsync --delete -avz --exclude uploads  -p 2828  -e ssh  10.13.7.122:/home/mydomain/public_html/   /home/mydomain/public_html/

4. If you want to exclude lots of files, you may use a text file to add entries and add “–exclude-from ‘/scripts/skipped.txt’

I created a text file ‘/scripts/skipped.txt’ where rsync executed. My ‘skipped.txt’ having the entries,

[root@rc-113 installation]# cat skipped.txt
uploads
wordpress/wp-config.php
system/application/config/database.php
js/parsed/
style/parsed/
system/cache/
system/logs/

And the rsync command is,

Eg:

/usr/bin/rsync --delete -avz --exclude-from '/scripts/skipped.txt'  -e ssh  10.13.7.122:/home/mydomain/public_html/   /home/mydomain/public_html/

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>