LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1477|回复: 9

备份自己的gentoo

[复制链接]
发表于 2007-12-3 17:18:46 | 显示全部楼层 |阅读模式
虽然备份自己的系统是个很老很老的问题了,
在这里大家谈谈自己是怎么做的
下面是我的做法希望对和我一样的新手有帮助( 前辈们别仍砖头~~)

我采用rsnapshot,主要是简单好用,实现增量备份
参见以下文章,虽是e文的还是好懂
大家都谈谈使用的感受
Once installed you'll need to make several changes to the configuration file /etc/rsnapshot.conf:

    * Setup the rotation periods.
    * Setup the list of directories/files to backup.
    * Optionally exclude files from the backups.

The only thing to remember is that when setting up keys and values in the configuration file you must specify them as Tab-separated. Why this choice was made I have no idea - syntactically significant whitespace should be regarded as evil IMHO.

Moving on the first thing you'll need to do is uncomment the various rotation periods:

interval        hourly  6
interval        daily   7
interval        weekly  4
interval        monthly 6

If these are left commented out (Comments are lines beginning with the '#' character) then nothing will happen.

The numbers listed against the names will control how often the backups are rotated, so by default you'll receive:

    * 6 hourly backups.
    * 7 daily backups.
    * 4 weekly backups.
    * 6 monthly backups.

Once these have been uncommented you'll need to setup the directories to backup. How this is done depends on the nature of the directories, local vs. remote.

A local directory will look like this:

# LOCALHOST
backup /home/          localhost/
backup /etc/           localhost/
backup /usr/local/     localhost/

(Remember that tabs are used to separate these values).

A remote system will instead look like this:

backup  root@hostname:/home/                hostname/
backup  root@hostname:/etc/                hostname/
backup  root@hostname:/usr/local/bin/   hostname/

The difference between these two samples is the second section of the lines; for local systems it is just a directory name with a trailing "/" character. For remote hosts you should use "login@full.hostname.com:/path".

The last field in the samples is the backup directory to use upon the localhost - by default the backups will be stored beneath "/var/cache/rsnapshot". You can change this by setting:

#
# Change the location where backups are stored.
#
snapshot_root        /mnt/nfs/backupstore

If you are setting up remote backups the system assumes the there is a password-less login setup between the local machine and the remote machine specified (root@hostname in this example).

If you've not setup key-based OpenSSH logins then now is a good time to do it.

Note that you don't need to use remote root logins unless the files you wish to backup are unreadable to ordinary users upon the machine you're backing up. (Although it's fair to say if you're backing up /etc you'll almost certainly wish to do so as root - as otherwise important files such as /etc/shadow will not be read).

Once you've configured your logins for remote machines, and setup the filepaths you wish to backup you only need to enable the cronjob used to run the backups.

To do that remove the "#" comment characters from the relevant lines in /etc/cron.d/rsnapshot file leaving you with :

# This is a sample cron file for rsnapshot.
# The values used correspond to the examples in /etc/rsnapshot.conf.
# There you can also set the backup points and many other things.
#
# To activate this cron file you have to uncomment the lines below.
# Feel free to adapt it to your needs.

0 */4   * * *           root    /usr/bin/rsnapshot hourly
30 3    * * *           root    /usr/bin/rsnapshot daily
0  3    * * 1           root    /usr/bin/rsnapshot weekly
30 2    1 * *           root    /usr/bin/rsnapshot monthly

The names used here "hourly", "daily", etc, match those used in the rsnapshot.conf file - which is important.

Once you've enabled the cronjobs you should be ready to make your first backup - which will take a while.

To do so run:

rsnapshot hourly

If all goes well you'll receive your backup files beneath "backup_root"/hourly.0/hostname, and any errors will be reported in the file /var/log/rsnapshot.log.

After a few days you'll notice that you have several new files such as:

root@scratchy:/mnt/backup# ls -l
total 68
drwxr-xr-x  4 root root  4096 2005-08-16 04:00 daily.0
drwxr-xr-x  4 root root  4096 2005-08-15 04:00 daily.1
drwxr-xr-x  4 root root  4096 2005-08-14 04:00 daily.2
drwxr-xr-x  4 root root  4096 2005-08-13 04:01 daily.3
drwxr-xr-x  4 root root  4096 2005-08-12 04:00 daily.4
drwxr-xr-x  4 root root  4096 2005-08-11 04:00 daily.5
drwxr-xr-x  4 root root  4096 2005-08-10 04:01 daily.6
drwxr-xr-x  4 root root  4096 2005-08-17 20:01 hourly.0
drwxr-xr-x  4 root root  4096 2005-08-17 16:00 hourly.1
drwxr-xr-x  4 root root  4096 2005-08-17 12:00 hourly.2
drwxr-xr-x  4 root root  4096 2005-08-17 08:01 hourly.3
drwxr-xr-x  4 root root  4096 2005-08-17 04:00 hourly.4
drwxr-xr-x  4 root root  4096 2005-08-17 00:01 hourly.5

These are the rotated backups which we've saved, the initial backups will be the largest - the later ones will only contain changes made since the previous run.

To see this you can view the amount of disk space taken up by each backup with "rsnapshot du":

root@scratchy:/mnt/backup# rsnapshot du
8.1G    /mnt/backup/hourly.0/
124M    /mnt/backup/hourly.1/
164M    /mnt/backup/hourly.2/
90M     /mnt/backup/hourly.3/
90M     /mnt/backup/hourly.4/
79M     /mnt/backup/hourly.5/
194M    /mnt/backup/daily.0/
199M    /mnt/backup/daily.1/
216M    /mnt/backup/daily.2/
189M    /mnt/backup/daily.3/
229M    /mnt/backup/daily.4/
224M    /mnt/backup/daily.5/
324M    /mnt/backup/daily.6/
11G     total

As the output shows the initial backup consumes a significant amount of disk space, and later ones only show the small amount of changes since then.

To reduce the space of the backups you can exclude files you don't care about, such as Apache logfiles. Simply add the filenames, or patterns, to the configuration file:

exclude access.log
exclude access.log.*
exclude error.log
exclude error.log.*
exclude referer.log
exclude referer.log.*
exclude agent.log
exclude agent.log.*
exclude Mail/backup/*
exclude /home/qemu
exclude Cache
exclude history.dat
exclude .bash_history
exclude viminfo

Note that any filename which matches the patterns will be excluded - so don't be too permissive or you might accidentally include a filename you did care about.

以下是我的配置文件,供大家参考!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2007-12-3 18:19:03 | 显示全部楼层
备份完之后有如下错误
...
ERROR: sys/module/vt/parameters/underline failed verification -- update discarded.
ERROR: sys/power/state failed verification -- update discarded.
rsync error: some files could not be transferred (code 23) at main.c(980) [sender=2.6.9]
日志提示如下

[03/Dec/2007:17:41:46] WARNING: /usr/bin/rsnapshot hourly: completed, but with some warnings

[03/Dec/2007:17:12:13] /usr/bin/rsnapshot hourly: started
[03/Dec/2007:17:12:13] mkdir -m 0755 -p /mnt/mdk/hourly.0/localhost/mnt/
[03/Dec/2007:17:12:13] /usr/bin/rsync -a --delete --numeric-ids --relative --delete-excluded --exclude=/mnt --exclude=/home --exclude=/var/tmp/portage --exclude=/var/tmp/ccache --exclude=mnt/mdk /. /mnt/mdk/hourly.0/localhost/mnt/mdk/
[03/Dec/2007:17:41:46] touch /mnt/mdk/hourly.0/
[03/Dec/2007:17:41:46] WARNING: /usr/bin/rsnapshot hourly: completed, but with some warnings

可否解决这些问题
回复 支持 反对

使用道具 举报

发表于 2007-12-3 20:34:43 | 显示全部楼层
我每个月打一次包,哈哈
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-3 22:51:51 | 显示全部楼层
Post by tpxc;1791069
我每个月打一次包,哈哈


你是自己手动打包?
回复 支持 反对

使用道具 举报

发表于 2007-12-4 08:11:32 | 显示全部楼层
占用地方大的tmp distfiles等目录都是lvm挂载的
需要备份的时候找个live cd或者辅助系统 挂载/
然后tar 一下就好了,方便 ...
回复 支持 反对

使用道具 举报

发表于 2007-12-4 14:21:33 | 显示全部楼层
Post by newsky_;1790976
虽然备份自己的系统是个很老很老的问题了,
在这里大家谈谈自己是怎么做的
下面是我的做法希望对和我一样的新手有帮助( 前辈们别仍砖头~~)

我采用rsnapshot,主要是简单好用,实现增量备份
参见以下文章,虽是e文的还是好懂
大家都谈谈使用的感受



以下是我的配置文件,供大家参考!

unmount所有的非Linux分区,然后
  1. # tar --exclude tmp --exclude var/tmp --exclude usr/portage/distfiles --exclude stage5.tar.bz2 -cvvjpf stage5.tar.bz2 [b][color="Red"]. [/color][/b]
复制代码
注意最后的“.”

另外一个办法是最小化备份
  1. # rm -rf /usr/portage/distfiles/* && rm -rf /var/tmp/portage/* && rm -rf /var/log/portage/*
  2. # tar cvvjpf --exclude=dev --exclude=proc --exclude=sys --exclude=tmp --exclude=stage5.tar.bz2  stage5.tar.bz2 .
复制代码

这种备份方法在restore的时候还要用以下命令手工建立系统文件
  1. # mkdir {dev,proc,tmp,sys} && chmod 1777 tmp && cd dev && MAKEDEV generic
复制代码
回复 支持 反对

使用道具 举报

发表于 2007-12-4 18:28:51 | 显示全部楼层
我也是自己打包,主要是把/usr/distfiles, /usr/portage,  /tmp /usr/tmp给exclude就行了。当然得用livecd做。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-4 23:45:28 | 显示全部楼层
Post by nainaide;1791510
我也是自己打包,主要是把/usr/distfiles, /usr/portage,  /tmp /usr/tmp给exclude就行了。当然得用livecd做。


用rsnapshot控制目录很方便的,并且采用增量方式,第一次较久以后就快了.
回复 支持 反对

使用道具 举报

发表于 2007-12-5 10:17:27 | 显示全部楼层
Post by newsky_;1791673
用rsnapshot控制目录很方便的,并且采用增量方式,第一次较久以后就快了.


tar也可以增量啊~一样也快。
回复 支持 反对

使用道具 举报

发表于 2007-12-6 04:10:16 | 显示全部楼层
我是用lvm,然后用lvm的快照功能直接备份系统,没有用辅助系统
Post by tpxc;1791219
占用地方大的tmp distfiles等目录都是lvm挂载的
需要备份的时候找个live cd或者辅助系统 挂载/
然后tar 一下就好了,方便 ...
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表