Archive

Posts Tagged ‘rsync’

Use rsync to strip hidden files

February 25th, 2009 Arthur Gressick No comments

Recently I was working on a project where I had some GIT repository files and also Apple HFS+ Extended attributes. I struggled for what seemed hours trying to figure out how to remove all of the .DS_File and .git. I remembered that there was rsync which I could use to EXCLUDE files. Now I am sure this could have been much cleaner and I am sure I will repost another in the futre but here are my command for. Remember to look at the files using the:

ls -la

Look for any of the files that begin with “.” and here are the commands I used.

rsync -r --exclude '._*' source_folder/ destination_folder/

I was in the folder already which had the source and folder hence the lacking of the “/” before the source and destination.

Here is another script:

rsync -r --exclude '.git*' source_folder/ destination_folder/

Crontab script for Rsync

February 25th, 2009 Arthur Gressick No comments

What is you could run a single script each night automatically and have the files from one server automatically copy to another for backup. Most people use a third party application for this or have copy scripts.

The point of this Rsync script is to sync the files that have changed so that we don’t make more work then is needed. This will compare the files from the source to the target then once if finds the files that need to be copied it will compress the files and then copy them to the destination server. I set up the script to run on a regular basis.

0 3 * * * rsync -avz --password-file=/password_file /path/to/folder/ USER@server.com::path/to/folder/

This will run every midnight at 12:03AM, archive mode + compress, use a password file, syncing source folder with destination folder with username.

Look for the directions on how to setup a rsync server. Also note that this should work fine on Mac OS X but I have not fully tested it on the OS.

Ubuntu Rsyncd Server

February 11th, 2009 Arthur Gressick No comments

The main purpose of this project was to build a server which could collect information from all of the outlying server and bring them to a central repository system. I like to use it for webserver so that I can have lets say 3 different flavors of linux running legacy systems. Backing those up is very cumbersome so having a CRONTAB job to automatically sync the files back to a central unit makes it much easier to restore them should anything happen to that server. Below is the information on how I created this on Ubuntu 8.10. I am sure it can be changed a bit to work on other systems.

Let install a couple of software apps on the server

apt-get install rsync
apt-get install xinetd

1. Edit /etc/default/rsync to start rsync as daemon using xinetd.

nano /etc/default/rsync

Now look for the following code below and change.

RSYNC_ENABLE=inetd

2. Create /etc/xinetd.d/rsync to launch rsync via xinetd.

nano /etc/xinetd.d/rsync

Now paste the information below:

service rsync
   {
      disable         = no
      socket_type     = stream
      wait            = no
      user            = root
      server          = /usr/bin/rsync
      server_args     = --daemon
      log_on_failure  += USERID
   }

3. Create /etc/rsyncd.conf configuration for rsync in daemon mode.

nano /etc/rsyncd.conf

Now paste the following information below:

ax connections = 5
log file = /var/log/rsync.log
timeout = 300
 
[rbackup]
comment = Public Share
path = /home/rbackup
read only = no
list = yes
uid = rbackup
gid = rbackup
auth users = rbackup
secrets file = /etc/rsyncd.secrets
hosts allow = 10.10.1.248

4. Create /etc/rsyncd.secrets for user’s password.

nano /etc/rsyncd.secrets

Now paste the following information below

user:password

Now change the permissions on the file

chmod 600 /etc/rsyncd.secrets

5. Start/Restart xinetd

/etc/init.d/xinetd restart

Now you can test this from another machine

rsync user@10.10.2.100::share

NOTE: is you want to setup a password file you will have to create it on the source server and then change the permissions on the file in order for it to work properly.

nano password

Just enter the password in the file no extra spaces or other characters then chmod the permissions

chmod 600 password

Example of a rsync script

rsync -avz --password-file=/password /DB_Backups/ user@10.10.2.100::share

There are tons of scripts you can run and also changing the flags to preserve the permissions of the files. Have fun!!