歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Unix知識 >> 關於Unix

unix下自動備份程序


注:我們公司裡一些服務器就是通過如下程序,自動備份到ftp服務器上。


08 01 * * 0,3,5 /home/jiang/backup/autobackup.sh

autobackup.sh程序如下:



#!/bin/bash
############### System Backup to FTP ################
#Power By Jiang Daoyou
#1. mkdir /home/jiang/backup
#2. chmod 700 autobackup.sh
#3. crontab -e
#System Setup
host="x.x.x.x" #ftp host
UserName=backupuser #ftp user name
Passwd=password #fto user password
backup_path="/home/jiang/backup" #set saved backup path
time=`/bin/date |awk '{print $6""$2""$3"_"$4}'|awk -F"_" '{print $2}'|awk -F: '{print $1""$2""$3}'`
file=webserver-$(date +%Y%m%d)$time.tar.gz
#################### backup ########################
#stop mysql database server
#/usr/bin/killall mysqld
#/etc/rc.c/init.d/mysqld stop 對於備份mysql要做適當修改
#sleep 5s #stop 5 second
#file tar
#tar -czf $backup_path/$file $backupfile
tar -czf $backup_path/$file /etc /var/log/daemon /var/log/server.log /var/log/httpd /var/log/cmdlog
sleep 5s
#start mysql database server
#/usr/local/mysql/bin/mysqld_safe --user=mysql & #set your mysqld path
#/etc/rc.d/init.d/mysqld start
cd $backup_path
sleep 2s
#file ftp
ftp -i -n < open $host
user $UserName $Passwd
cd pptpserver
bin
mput $file
bye
!
#sleep 10s
rm -rf $backup_path/$file
Copyright © Linux教程網 All Rights Reserved