Archive for the tag 'RSYNC'

We can set up an automatic rsync and place the files into daily folders. For this to work we need to setup automatic ssh login first and then use cron to run your bash script.

The base of the automatic rsync is a very simple bash script.

#!/bin/bash
dest=/backup/buddy/`date +%A`
mkdir -p $dest
rsync -e ’ssh -p 2222′ -avl –delete –stats –progress root@192.168.1.1:/home/buddy $dest/

Using Cron to run the above script every day.

# run rsync at 23.00hrs every day
00 23 * * * sh /home/backup/bin/backup
SBDavid

Backing up your files with rsync

Backing up your files with rsync

rsync makes the task a lot easier as it only downloads files that have changed - saving time and bandwidth.

Setup ssh keys so that you don’t need to enter a password each time you attempt to rsync folders.

On the destination server, the command is as follows:

rsync -e ’ssh -p 2222′ -avl –delete –stats –progress root@192.168.1.1:/home/buddy /backup/

-e ’ssh -p 2222′: this ensures rsync uses the SSH protocol and sets the port.

-avl: This contains three options;

(a) is archive mode which basically keep the permission settings for the files.
(v) is verbose mode. You can leave it out or increase it by appending two v’s (-vv).
(l) preserves any links you may have created.

–delete: deletes files from the destination folder that are no longer required (i.e. they have been deleted from the folder being backed up).

–stats: Adds a little more output regarding the file transfer status.

–progress: shows the progress of each file transfer. Can be useful to know if you have large files being backup up.

SBDavid

rsync - exclude files and folders

rsync - exclude files and folders

First - define the files and folders you want to exclude from the rsync:

To do this create a file called ‘exclude.txt’ on the destination machine (the system you give the rsync command on):

pico /home/buddy/exclude.txt

Now we have defined what to exclude we can direct rsync to the file with:

–exclude-from ‘/home/buddy/exclude.txt’

The final command would be:

rsync -e ’ssh -p 2222′ -avl –delete –stats –progress –exclude-from ‘/home/buddy/exclude.txt’ root@192.168.1.1:/home/buddy /backup/

rsync to backup your home directory and mysql databases.

Run the below rsync command using “nohup”, nohup runs a command immune to hangups, with output to a non-tty.

Rsync your home directory’s to your backup server.

Replace $IP with the IP address for your production server.

Run the below commands from your backup server.

#rsync -vrplogDtH –exclude=virtfs/ –progress -e ssh root@$IP:/home/ /home/

rsync all mysql databases.

#rsync -vrplogDtH –progress -e ssh root@$IP:/var/lib/mysql/ /var/lib/mysql/

Backup DB server_support

rsync -vrplogDtH –progress -e ssh root@$IP:/var/lib/mysql/server_support /var/lib/mysql/
SBDavid

rsnapshot filesystem backup utility

rsnapshot is a filesystem backup utility based on rsync.

Using rsnapshot, it is possible to take snapshots of your filesystems at different points in time. Using hard links, rsnapshot creates the illusion of multiple full backups, while only taking up the space of one full backup plus differences. When coupled with ssh, it is possible to take snapshots of remote filesystems as well.

rsnapshot is written in Perl, and depends on rsync. OpenSSH, GNU cp, GNU du, and the BSD logger program are also recommended, but not required.

All of these should be present on most Linux systems.

By default, the installation procedure will install all files under /usr/local. If you’ve followed these instructions so far, you will have configured rsnapshot to be installed under /usr/local, with the config file in /etc.

Under these circumstances, it will be necessary to become root to install the program. Now is the time to do so. You will, of course, need the root password to do this:

su

This will prompt you for the root password.

Now, to install rsnapshot, run the following command:

make install

This will install rsnapshot with all the settings you specified in the ./configure stage. If all goes well, you will have the following files on your system:

/usr/local/bin/rsnapshot The rsnapshot program
/usr/local/man/man1/rsnapshot.1 Man page
/etc/rsnapshot.conf.default The example config file

The latest version of the program and this document can always be found at http://www.rsnapshot.org/.

Next »