Linux下的系统备份

应用背景

系统中比较重要的目录有/home等,你现在想在每天2:45am进行备份,且数据备份到/backup内,并使用tar将备份数据打包,如何处理?
 
解决方案
第一步:编辑备份脚本如下:
[root@localhost backup]# vim /root/bin/backup.sh
 
#!/bin/bash
backdir="/home"
basedir=/backup
[ ! -d "$basedir" ] && mkdir $basedir
backfile=$basedir/backup.tar.gz
tar -zcvf $backfile $backdir
 
第二步:编辑/etc/crontab进行系统备份,关键代码见最后一行
[root@localhost backup]# vim /etc/crontab
 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
 
# For details see man 4 crontabs
 
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
45 2 * * * root sh /root/bin/backup.sh

 

猜你喜欢

转载自cakin24.iteye.com/blog/2335930