UNIX / Linux:Rsnapshot 恢复备份
我已经使用本教程在 Redhat和Debian Linux 系统下创建了备份服务器。如何使用 rsnapshot 备份工具恢复文件(例如 /var/www/html)?如何在 UNIX 或 Linux 操作系统下使用 rsnapshot 恢复 MySQL 数据库转储?
您可以使用 scp 或 rsync 命令本身来恢复备份。您只需从快照根目录复制所有文件即可。每小时备份将比每日备份更新,每日备份将比每周备份更新,每周备份将比每月备份更新。
Remote location +------------------------+ Internets | Backup.example.net.in | -----------+ +------------------------+ | +---------+---------+ | Local ISP Router | +-------------------+ | Lan +---------+--+---------+--+-------+---+---------------------------------+ | Server1 | | Server2 | | Tomcat| | User desktops and other systems | +---------+ +---------+ +-------+ +---------------------------------+ Apache MySQL JavaApp
登录 Backup.example.net.in,输入:
# ssh user@backup.example.net.in
Cd 到您的 rsnapshot 目录:
# cd /.raid/rsnapshot
要列出当前快照,请输入:
# ls -l
示例输出:
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
server1 的每日备份存储在 /.raid/rsnapshot/daily.*/server1/ 目录中。要查看最新的每日备份 (daily.0),请输入:
# cd /.raid/rsnapshot/daily.0/server1/
# ls -l
如何从备份服务器本身恢复文件?
您可以使用 rsync 将备份恢复到 server1,如下所示以恢复 /var/www/html/:
或者使用 scp 命令复制选定的文件,例如 /var/www/html/db.conf.php:
# cd /.raid/rsnapshot/daily.0/server1/var/www/html/
# rsync -avr * user@server1.example.net.in:/var/www/html/
# scp db.conf.php user@server1.example.net.in:/var/www/html/
如何从Server2本身恢复文件?
您可以使用 rsync 命令从 backup.example.net.in 恢复文件,如下所示。登录到 server2.example.net.in 并输入以下命令:
或者使用 scp 命令复制单个文件,例如 /.raid/rsnapshot/daily.0/server1/var/www/html/db1/db.conf.py:
# cd /var/www/html/
# rsync -avr user@backup.example.net.in:/.raid/rsnapshot/daily.0/server1/var/www/html/* .
# cd /var/www/html/
# scp user@backup.example.net.in:/.raid/rsnapshot/daily.0/server1/var/www/html/dir1/db.conf.py .
如何恢复 MySQL 备份?
如果您使用此 shell 脚本创建 mysql 快照,则从 /.raid/rsnapshot/ 目录复制数据库转储。首先,登录到 backup.example.net.in 并键入以下命令以列出最新的每日 (daily.0) 备份:
示例输出:
# cd /.raid/rsnapshot/daily.0/mysql/
# ls -l
total 16 drwxr-xr-x 3 root root 4096 Feb 4 2010 mysql1.example.net.in drwxr-xr-x 3 root root 4096 Feb 4 2010 java1.mysql.example.in drwxr-xr-x 3 root root 4096 Feb 4 2010 mysqlmaster1.vsnl.example.net.in drwxr-xr-x 3 root root 4096 Jul 27 2010 mysqlmaster2.bsnl.example.net.in
要恢复 mysql1.example.net.in 备份,请输入:
# cd mysql1.example.net.in
要列出当前数据库,请输入:
# ls -l
示例输出:
-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
要恢复 wordpress.18_05_47pm.gz,请使用 scp 命令将数据库复制到 mysql 服务器,即 server2.example.net.in,输入:
# scp wordpress.18_05_47pm.gz root@server2.example.net.in:/root
从 backup.example.net.in 注销并登录到 server2.example.net.in。要解压文件,请输入:
要恢复 mysql 备份,请输入:
简而言之,从 wordpress.18_05_47pm 文件恢复 wordpress 数据库,请输入:
# cd /root
# gunzip wordpress.18_05_47pm.gz
# mysql -u root -p'YOUR-PASSWORD-HERE' -h locahost YOUR-DB-NAME-HERE < YOUR-BACKUP.sql.FILE-HERE
# mysql -u root -p'mySecrete' -h locahost wordpress < wordpress.18_05_47pm