Monday, April 1, 2013

Backup with rsnapshot utility

[root@test ~]# cd /usr/local/src/
[root@test src]# wget http://www.rsnapshot.org/downloads/rsnapshot-1.3.1.tar
.gz
--2013-01-14 05:16:24--  http://www.rsnapshot.org/downloads/rsnapshot-1.3.1.tar.
gz
Resolving www.rsnapshot.org... 208.92.64.114
Connecting to www.rsnapshot.org|208.92.64.114|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 215806 (211K) [application/x-gzip]
Saving to: “rsnapshot-1.3.1.tar.gz”

100%[======================================>] 215,806     39.8K/s   in 5.3s

2013-01-14 05:16:31 (39.8 KB/s) - “rsnapshot-1.3.1.tar.gz” saved [215806/215806]

[root@test src]# tar -zxvf rsnapshot-1.3.1.tar.gz
rsnapshot-1.3.1/
rsnapshot-1.3.1/rsnapshot-preamble.pl
rsnapshot-1.3.1/rsnapshot-program.pl
rsnapshot-1.3.1/rsnapshot-diff.pl
rsnapshot-1.3.1/rsnapshot.conf.default.in
rsnapshot-1.3.1/rsnapshot.1
rsnapshot-1.3.1/rsnapshot-diff.1
rsnapshot-1.3.1/AUTHORS
rsnapshot-1.3.1/COPYING
rsnapshot-1.3.1/INSTALL
rsnapshot-1.3.1/README
rsnapshot-1.3.1/TODO
rsnapshot-1.3.1/NEWS
rsnapshot-1.3.1/ChangeLog
rsnapshot-1.3.1/docs/
rsnapshot-1.3.1/docs/HOWTOs/
rsnapshot-1.3.1/docs/HOWTOs/rsnapshot-HOWTO.en.html
rsnapshot-1.3.1/docs/HOWTOs/rsnapshot-Mac-howto
rsnapshot-1.3.1/docs/HOWTOs/rsnapshot-windows-howto
rsnapshot-1.3.1/docs/Upgrading_from_1.1
rsnapshot-1.3.1/Makefile.am
rsnapshot-1.3.1/Makefile.in
rsnapshot-1.3.1/aclocal.m4
rsnapshot-1.3.1/configure[root@gai-1397 rsnapshot-1.3.1]# ./configure --sysconfdir=/etc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make sets $(MAKE)... (cached) yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for perl... /usr/bin/perl
checking for rsync... /usr/bin/rsync
checking for cp... /bin/cp
checking for rm... /bin/rm
checking for ssh... /usr/bin/ssh
checking for logger... /usr/bin/logger
checking for du... /usr/bin/du
configure: creating ./config.status
config.status: creating Makefile
config.status: creating rsnapshot
config.status: creating rsnapshot-diff
config.status: creating rsnapshot.conf.default
config.status: creating t/support/etc/configtest.conf
config.status: creating t/support/etc/rsync.conf
config.status: creating t/support/etc/gnu_cp.conf
config.status: creating t/support/etc/relative_delete_bugfix.conf
config.status: creating t/configtest.t
config.status: creating t/rsync.t
config.status: creating t/gnu_cp.t
config.status: creating t/relative_delete_bugfix.t

Now type  "make test"    to run the regression test suite.
Then type "make install" to install the program.

After rsnapshot is installed, don't forget to copy
/etc/rsnapshot.conf.default to /etc/rsnapshot.conf



[root@test rsnapshot-1.3.1]# make install
/usr/bin/pod2man -c '' -n 'rsnapshot' -r '' rsnapshot > rsnapshot.1
/usr/bin/pod2man -c '' -n 'rsnapshot-diff' -r '' rsnapshot-diff > rsnapshot-diff.1
make[1]: Entering directory `/usr/local/src/rsnapshot-1.3.1'
test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
 /usr/bin/install -c 'rsnapshot' '/usr/local/bin/rsnapshot'
 /usr/bin/install -c 'rsnapshot-diff' '/usr/local/bin/rsnapshot-diff'
test -z "/etc" || mkdir -p -- "/etc"
 /usr/bin/install -c -m 644 'rsnapshot.conf.default' '/etc/rsnapshot.conf.default'
test -z "/usr/local/man/man1" || mkdir -p -- "/usr/local/man/man1"
 /usr/bin/install -c -m 644 './rsnapshot.1' '/usr/local/man/man1/rsnapshot.1'
 /usr/bin/install -c -m 644 './rsnapshot-diff.1' '/usr/local/man/man1/rsnapshot-diff.1'
make[1]: Leaving directory `/usr/local/src/rsnapshot-1.3.1'

[root@test ~]# cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf.

[root@test ~]# cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf
[root@test ~]# vi /etc/rsnapshot.conf
[root@test ~]# mkdir /test
[root@test ~]# cd /public/
[root@test public]# ls
c  CentOS-6.3-i386-LiveDVD.iso  lost+found  packages
[root@test public]# cd ..
root@test ~]# rsnapshot configtest
Syntax OK

[root@test ~]# rsnapshot -t hourly
echo 5875 > /var/run/rsnapshot.pid
mkdir -m 0700 -p /.snapshots/
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded /home \
    /.snapshots/hourly.0/localhost/
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
    /public /.snapshots/hourly.0/testing/
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded /etc \
    /.snapshots/hourly.0/localhost/
mkdir -m 0755 -p /.snapshots/hourly.0/
/usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded \
    /usr/local /.snapshots/hourly.0/localhost/
touch /.snapshots/hourly.0/
[root@test ~]# rsnapshot -t daily
echo 5885 > /var/run/rsnapshot.pid
mkdir -m 0700 -p /.snapshots/
/.snapshots/hourly.5 not present (yet), nothing to copy


scripts that are executed before and after the backup
Code:

cmd_preexec    /home/test/backup/pre.sh
cmd_postexec    /home/test/backup/post.sh

pre.sh

Code:

screen -S test -X stuff "say Starting backup. World is Readonly! $(printf '\r')"
screen -S test -X stuff "save-off $(printf '\r')"
screen -S test -X stuff "save-all $(printf '\r')"


post.sh

Code:

screen -S test -X stuff "save-on $(printf '\r')"
screen -S test -X stuff "say Backup complete. World back to Readwrite $(printf '\r')"

[root@test ~]# ls -al /.snapshots/hourly.0/
total 16
drwxr-xr-x 4 root root 4096 Jan 14 06:34 .
drwx------ 3 root root 4096 Jan 14 06:33 ..
drwxr-xr-x 5 root root 4096 Jan 14 06:33 localhost
drwxr-xr-x 3 root root 4096 Jan 14 06:33 testing

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

No comments: