20080803

Linux SHELL備份

掛了那麼多次,該學乖了
來個備份吧
backup.sh

#!/bin/bash
#備份位置
backup_path="/home/max/sdb/backup/"
#www位置
www_path='/home/max/www'
#mysql位置
mysql_path='/var/lib/mysql'

#今天的日期
day=`date +%Y-%m-%d`
#刪除舊資料的日期,預設七天前
del_day=`date --date='7 days ago' +%Y-%m-%d`

#前除7天前備份
rm -rf ${backup_path}www$del_day.tar.gz
rm -rf ${backup_path}mysql$del_day.tar.gz


#備份www所有內容
tar -zcf ${backup_path}www$day.tar.gz $www_path

#備份mysql
service mysqld stop
tar -zcf ${backup_path}mysql$day.tar.gz $mysql_path
service mysqld start

#備份DNS設定
mkdir ${backup_path}named
cp -a /var/named/chroot/var/named/*.* "$backup_path"named/
tar -zcf ${backup_path}named$day.tar.gz ${backup_path}named
rm -rf "$backup_path"named/

#備分etc
mkdir ${backup_path}etc
cp -a /etc/named.conf "$backup_path"etc
cp -a /etc/my.cnf "$backup_path"etc
cp -a /etc/php.ini "$backup_path"etc
cp -a /etc/httpd/conf/httpd.conf "$backup_path"etc
tar -zcf ${backup_path}etc$day.tar.gz ${backup_path}etc
rm -rf "$backup_path"etc

沒有留言: