Monday, April 23, 2012

UNIX / Linux: Rsnapshot Restore Backups

I've created the backup server using this tutorial under Redhat and Debian Linux systems. How do I restore files (such as /var/www/html) with rsnapshot backup tool? How do I restore MySQL database dumps with rsnapshot under UNIX or Linux operating systems?

You can restore backups using the scp or rsync command itself. You can just copy all the files from your snapshot root. The hourly backups will be more recent than the daily backups, and the daily backups will be more recent than the weeklys and the weekly more recent than the monthlys.
   Remote location
+------------------------+ Internets
| Backup.nixcraft.net.in | -----------+
+------------------------+ |
+---------+---------+
| Local ISP Router |
+-------------------+
| Lan
+---------+--+---------+--+-------+---+---------------------------------+
| Server1 | | Server2 | | Tomcat| | User desktops and other systems |
+---------+ +---------+ +-------+ +---------------------------------+
Apache MySQL JavaApp
Login to Backup.nixcraft.net.in, enter:
# ssh user@backup.nixcraft.net.in
Cd to your rsnapshot directory:
# cd /.raid/rsnapshot
To list current snapshots, enter:
# ls -l
Sample outputs:
drwxr-xr-x 18 root root 4096 Jan 26 00:09 daily.0
drwxr-xr-x 18 root root 4096 Jan 25 00:09 daily.1
drwxr-xr-x 18 root root 4096 Jan 24 00:06 daily.2
drwxr-xr-x 18 root root 4096 Jan 23 00:06 daily.3
drwxr-xr-x 18 root root 4096 Jan 22 00:06 daily.4
drwxr-xr-x 18 root root 4096 Jan 21 00:07 daily.5
drwxr-xr-x 18 root root 4096 Jan 20 00:10 daily.6
drwxr-xr-x 18 root root 4096 Jan 27 08:08 hourly.0
drwxr-xr-x 18 root root 4096 Jan 27 04:08 hourly.1
drwxr-xr-x 18 root root 4096 Jan 27 00:10 hourly.2
drwxr-xr-x 18 root root 4096 Jan 26 20:07 hourly.3
drwxr-xr-x 18 root root 4096 Jan 26 16:07 hourly.4
drwxr-xr-x 18 root root 4096 Jan 26 12:08 hourly.5
drwxr-xr-x 18 root root 4096 Dec 5 00:10 monthly.0
drwxr-xr-x 18 root root 4096 Oct 31 00:10 monthly.1
drwxr-xr-x 18 root root 4096 Oct 3 00:12 monthly.2
drwxr-xr-x 18 root root 4096 Jan 16 00:12 weekly.0
drwxr-xr-x 18 root root 4096 Jan 9 00:12 weekly.1
drwxr-xr-x 18 root root 4096 Jan 2 00:12 weekly.2
drwxr-xr-x 18 root root 4096 Dec 26 00:11 weekly.3
The daily backups for server1 is stored at /.raid/rsnapshot/daily.*/server1/ directory. To see latest daily backup (daily.0), enter:
# cd /.raid/rsnapshot/daily.0/server1/
# ls -l

How Do I Restore Files From the Backup Server Itself?

You can restore backups to server1 using the rsync as follows to restore /var/www/html/:
# cd /.raid/rsnapshot/daily.0/server1/var/www/html/
# rsync -avr * user@server1.nixcraft.net.in:/var/www/html/

OR use the scp command to copy selected file such as /var/www/html/db.conf.php:
# scp db.conf.php user@server1.nixcraft.net.in:/var/www/html/

How Do I Restore Files From the Server2 Itself?

You can restore files from the backup.nixcraft.net.in using the rsync command as follows. Login to the server2.nixcraft.net.in and type the following commands:
# cd /var/www/html/
# rsync -avr user@backup.nixcraft.net.in:/.raid/rsnapshot/daily.0/server1/var/www/html/* .

OR use the scp command to copy a single file such as /.raid/rsnapshot/daily.0/server1/var/www/html/db1/db.conf.py:
# cd /var/www/html/
# scp user@backup.nixcraft.net.in:/.raid/rsnapshot/daily.0/server1/var/www/html/dir1/db.conf.py .

How Do I Restore MySQL Backups?

If you are using this shell script to create mysql snapshots then copy database dump from /.raid/rsnapshot/ directory. First, login to backup.nixcraft.net.in and type the following command to list the latest daily (daily.0) backups:
# cd /.raid/rsnapshot/daily.0/mysql/
# ls -l

Sample outputs:
total 16
drwxr-xr-x 3 root root 4096 Feb 4 2010 mysql1.nixcraft.net.in
drwxr-xr-x 3 root root 4096 Feb 4 2010 java1.mysql.nixcraft.in
drwxr-xr-x 3 root root 4096 Feb 4 2010 mysqlmaster1.vsnl.nixcraft.net.in
drwxr-xr-x 3 root root 4096 Jul 27 2010 mysqlmaster2.bsnl.nixcraft.net.in
To restore mysql1.nixcraft.net.in backup, enter:
# cd mysql1.nixcraft.net.in
To list current databases, enter:
# ls -l
Sample outputs:
-rw-r--r-- 1 root root  1631127 Jan 26 00:06 c_sales_final.18_05_18pm.gz
-rw-r--r-- 1 root root 1286946 Jan 26 00:06 support_wiki.18_05_22pm.gz
-rw-r--r-- 1 root root 8153091 Jan 26 00:06 support_forum.18_05_23pm.gz
-rw-r--r-- 1 root root 5862770 Jan 26 00:06 accounting.18_05_27pm.gz
-rw-r--r-- 1 root root 2158235 Jan 26 00:06 www_stats.18_05_31pm.gz
-rw-r--r-- 1 root root 415 Jan 26 00:06 information_schema.18_05_18pm.gz
-rw-r--r-- 1 root root 15643585 Jan 26 00:06 frontend_apache.18_05_38pm.gz
-rw-r--r-- 1 root root 7181723 Jan 26 00:06 wordpress.18_05_47pm.gz
To restore wordpress.18_05_47pm.gz use the scp command to copy database to mysql server i.e. server2.nixcraft.net.in, enter:
# scp wordpress.18_05_47pm.gz root@server2.nixcraft.net.in:/root
Logout from backup.nixcraft.net.in and login to the server2.nixcraft.net.in. To decompress file, enter:
# cd /root
# gunzip wordpress.18_05_47pm.gz

To restore the mysql backup, enter:
# mysql -u root -p'YOUR-PASSWORD-HERE' -h locahost YOUR-DB-NAME-HERE < YOUR-BACKUP.sql.FILE-HERE
In short restore wordpress database from wordpress.18_05_47pm file, enter:
# mysql -u root -p'mySecrete' -h locahost wordpress < wordpress.18_05_47pm

No comments:

Post a Comment