UNIX/Linux:Rsnapshot还原备份

时间:2020-01-09 10:43:16  来源:igfitidea点击:

我已经在Redhat和Debian Linux系统下使用本教程创建了备份服务器。
如何使用rsnapshot备份工具还原文件(例如/var/www/html)?
如何在UNIX或者Linux操作系统下使用rsnapshot恢复MySQL数据库转储?

您可以使用scp或者rsync命令本身还原备份。
您可以只从快照根目录复制所有文件。
每小时备份将比每日备份更新,并且每日备份将比每周备份更新,并且每周备份要比每月备份更新。

Remote location
+------------------------+   Internets
| Backup.theitroad.com | -----------+
+------------------------+            |
                             +---------+---------+
                             | Local ISP Router  |
                             +-------------------+
                                       | Lan
+---------+--+---------+--+-------+---+---------------------------------+
| Server1 |  | Server2 |  | Tomcat|   | User desktops and other systems |
+---------+  +---------+  +-------+   +---------------------------------+
  Apache        MySQL        JavaApp

登录到Backup.theitroad.com,执行:

# ssh [email protected]

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 /:

# cd /.raid/rsnapshot/daily.0/server1/var/www/html/
# rsync -avr * [email protected]:/var/www/html/

或者使用scp命令复制选定的文件,例如/var/www/html/db.conf.php:

# scp db.conf.php [email protected]:/var/www/html/

如何从Server2本身还原文件?

您可以使用rsync命令从backup.theitroad.com中还原文件,如下所示。
登录到server2.theitroad.com并执行以下命令:

# cd /var/www/html/
# rsync -avr [email protected]:/.raid/rsnapshot/daily.0/server1/var/www/html/* .

或者使用scp命令复制单个文件,例如/.raid/rsnapshot/daily.0/server1/var/www/html/db1/db.conf.py:

# cd /var/www/html/
# scp [email protected]:/.raid/rsnapshot/daily.0/server1/var/www/html/dir1/db.conf.py .

如何还原MySQL备份?

如果使用此Shell脚本创建mysql快照,则从/.raid/rsnapshot/目录复制数据库转储。
首先,登录backup.theitroad.com并执行以下命令以列出最新的每日(daily.0)备份:

# cd /.raid/rsnapshot/daily.0/mysql/
# ls -l

输出示例:

total 16
drwxr-xr-x 3 root root 4096 Nov  4  2010 mysql1.theitroad.com
drwxr-xr-x 3 root root 4096 Nov  4  2010 java1.mysql.theitroad.com
drwxr-xr-x 3 root root 4096 Nov  4  2010 mysqlmaster1.vsnl.theitroad.com
drwxr-xr-x 3 root root 4096 May 27  2010 mysqlmaster2.bsnl.theitroad.com

要在备份中还原mysql1.theitroad.net。
,请执行:

# cd mysql1.theitroad.com

要列出当前数据库,请执行:

# 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.theitroad.com,执行:

# scp wordpress.18_05_47pm.gz [email protected]:/root

从backup.theitroad.com注销,然后登录到server2.theitroad.com。
要解压缩文件,请执行:

# cd /root
# gunzip wordpress.18_05_47pm.gz

要恢复mysql备份,请执行:

# mysql -u root -p'YOUR-PASSWORD-HERE' -h locahost YOUR-DB-NAME-HERE < YOUR-BACKUP.sql.FILE-HERE

简而言之,从wordpress.18_05_47pm文件恢复wordpress数据库,执行:

# mysql -u root -p'mySecrete' -h locahost wordpress < wordpress.18_05_47pm