Showing posts with label RSYNC. Show all posts
Showing posts with label RSYNC. Show all posts

How To Backup Remote Linux Host Using rsnapshot rsync Utility

0 comments

In the previous article we reviewed how to backup local unix host using rsnapshot utility.


In this article, let us review how to backup remote Linux host using this utility.




1. Setup Key Based Authentication


As we’ve explained earlier setup the key based authentication as explained either in ssh-keygen and ssh-copy-id article or openSSH article.



[root@local-host]# ssh-keygen

[root@local-host]# ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

2. Verify the password less login between servers


Login to the remote-host from local-host without entering the password.



[root@local-host]# ssh remote-host
Last login: Sun Mar 15 16:45:40 2009 from local-host

[root@remote-host]#

3. Configure rsnapshot and specify Remote Host Backup Directories


Define your remote-host destination backup directories in /etc/rsnapshot.conf as shown below. In this example,




  • root@remote-host:/etc – Source directory on the remote-host that should be backed-up. i.e remote backup destination directory.

  • remote-host-backup/ – destination directory where the backup of the remote-host will be stored. Please note that this directory will be created under local-host /.snapshots/{internal.n}/ directory as shown in the last step.


# vi /etc/rsnapshot.conf

backup root@remote-host:/etc/ remote-host-backup/ exclude=mtab,exclude=core

4. Test rsnapshot Configuration


Perform configuration test to make sure rsnapshot is setup properly and ready to perform Linux rsync backup.



# rsnapshot configtest
Syntax OK

5. Add Crontab Entry for rsnapshot


Once you’ve verified that the rsync hourly and daily backup configurations are setup properly in the rsnapshot cwrsync utility, it is time to set this puppy up in the crontab as shown below.



# crontab -e
0 */4 * * * /usr/local/bin/rsnapshot hourly
30 23 * * * /usr/local/bin/rsnapshot daily

Check out Linux crontab examples article to understand how to setup and configure crontab.



6. Manually test the remote-host backup once


[root@local-host]# /usr/local/bin/rsnapshot hourly

[root@local-host]# ls -l /.snapshots/hourly.0/
total 8
drwxr-xr-x 3 root root 4096 Jul 22 04:19 remote-host-backup
drwxr-xr-x 3 root root 4096 Jul 13 05:07 localhost

[root@local-host]# ls -l /.snapshots/hourly.0/remote-host-backup/
total 4
drwxr-xr-x 93 root root 4096 Jul 22 03:36 etc

Troubleshooting Tips


Problem: rsnapshot failed with ERROR: /usr/bin/rsync returned 20 as shown below.



[root@local-host]# /usr/local/bin/rsnapshot hourly
rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(260)
[receiver=2.6.8]
----------------------------------------------------------------------------
rsnapshot encountered an error! The program was invoked with these options:
/usr/local/bin/rsnapshot hourly
----------------------------------------------------------------------------
ERROR: /usr/bin/rsync returned 20 while processing copyman@192.168.2.2:/etc/

Solution: This typically happens when the users who is performing the rsnapshot (rsync) doesn’t have access to the remote directory that you are trying to backup. Make sure the remote host backup directory has appropriate permission for the user who is trying to execute the rsnapshot.

RSYNC to backup your home DIR from your OLD server to New

0 comments

rsync -vrplogDtH –exclude=virtfs/ –progress -e ssh root@old-server-ip-address:/home/ /home/



g?^g????_?????~g????-?¢?_g????~????_g????? ????PuShKaR

?»??_?????^?????_?????~??V?_????? - ?Ú?????«?

g?^g????_?????~g????-?¢?_g????~????_g????? ????PuShKaR

?»??_?????^?????_?????~??V?_????? ?Ú?????

«g?^g????_?????~g????-?¢?_g????~????_g????? ????PuShKaR

?»??_?????^?????_?????~??V?_????? - ?Ú?????«?


Rsync

0 comments

rsync –delete –stats -vae ssh 66.249.137.130:/backup/cpbackup/daily/ /backup/cpbackup/daily/ –exclude-from ‘/root/exclude.txt’


I added the file exclude.txt because with this code you can have certain files not be transferred. In this case I added pending and spam emails.


So my exclude.txt file has this in it:


*.*.dwhs1234.dwhs.net


*.*.dwhs1234.dwhs.net:2,


*.*.dwhs1234.dwhs.net:2,*


*.msg”
core.*
*.*.mbox:2,


This is for a cpanel based server.

RSYNC

0 comments
rsync utility is used for synchronising files one of the major adavantage of rsync is that rsync can preserve permissions and ownership information, copy symbolic links, and generally is designed to intelligently handle your files

The basic syntax for rsync is simple enough -- just run


rsync [options] source destination

If you want to rsync the contents from /home/mabin/ to /var/www/html/ the command 

rsync -a /home/mabin /var/www/html

Whe doing rsync there is a big meaning in the ending '/' because if I rsync /home/mabin/ then only the contents inside the folder mabin will be copied.....but if didn't used the '/' ie /home/mabin then the entire directory will be taken ..that is a directory named mabin will be created at the destination

some switches with rsync
-----------------------------
-a --> archive option, which actually combines several rsync options. It combines the recursive and copy symlinks options, preserves group and owner, and generally makes rsync suitable for making archive copies. Note that it doesn't preserve hardlinks

-H --> Copies hard link

-v --> verbose mode

-z --> Compress option, will compress the data during transfer

--delete --> For deleting the already transferred data from source (a dangerous option, try to avoid it)

--exclude=".*/" --> To avoid copying hidden files. With this option you can avoid copying any particular file( If you dont want to copy .php files then pot it like this --exclude="*.php/"

sample command for local copying

rsync -avh /home/mabin/ /var/www/html

Rsync for remote copying

rsync -avhe ssh /home/user/dir/
user@remote.host.com:dir/


If you want to know how fast the transfer is going use the --progress option

rsync --progress -avhe ssh /home/user/dir/ user@remote.host.com:dir/