Board logo

主題: [分享]備份心得記錄 [打印本頁]

發表人: MU    時間: 2008-10-13 09:26 PM     主題: [分享]備份心得記錄

#!/bin/bash
#
# This program is created by VBird 2002/06/13
#
# What is this program?
#       This program will backup the following messages:
#       1. MySQL data files ( /var/lib/mysql );
#       2. HTTP's CGI-directory ( /var/www/cgi-bin )
#
# HOW TO RUN THIS PROGRAM?
#       Just put the file into /etc/crontab job,
#       or put this file's link file to /etc/cron.daily!
#
###############################################################
# History
#  Date         What                                    Who
#==============================================================
# 2002/06/13    First time to run this program
#               The only backup files are MySQL and CGI VBird
#==============================================================
# 0. Get the date messages and backup directory
day=`date +%Y-%m-%d`
backup_dir="/home/scn/disk2/backup/daily"

#!欲備份的目錄
#dir1="/var/www/html/sfs3"
dir2="/var/lib/mysql/sfs3"

#!備份後的檔名
#targetfile1="sfs3html-"`date '+%y-%m-%d'`.tar.gz
targetfile2="sfs3data-"`date '+%y-%m-%d'`.tar.gz

#!執行tar打包
#tar zcvf $backup_dir/$targetfile1 $dir1
tar zcvf $backup_dir/$targetfile2 $dir2

#!mysql資料庫資訊
databasename="sfs3"
rootpassword="scl0380"

#!sql匯出後的檔名
sqlfilename="sfs3sql-"`date '+%y-%m-%d'`.sql

#!以root身份利用mysqldump指令匯出sfs3資料庫資料
mysqldump $databasename > $backup_dir/$sqlfilename -uroot -p$rootpassword

#!zip壓縮匯出檔

zip $backup_dir/$sqlfilename.zip $backup_dir/$sqlfilename

#!只保留zip檔請執行下列指令 不刪除請保留#
rm -rf $backup_dir/$sqlfilename


#!切換到存放目錄
cd $backup_dir


#!設定ftp帳號密碼與存放目錄
host="172.16.0.2"
user="administrator"
password="nt6908"
replace_dir="daily"


#!啟動ftp連接

ftp -in << EOF
open $host
user $user $password
cd $replace_dir
bin
put $targetfile2
put $sqlfilename.zip
EOF
發表人: MU    時間: 2008-10-13 09:28 PM

#!/bin/bash
#
# This program is created by VBird 2002/06/13
#
# What is this program?
#       This program will backup the following messages:
#       1. MySQL data files ( /var/lib/mysql );
#       2. HTTP's CGI-directory ( /var/www/cgi-bin )
#
# HOW TO RUN THIS PROGRAM?
#       Just put the file into /etc/crontab job,
#       or put this file's link file to /etc/cron.daily!
#
###############################################################
# History
#  Date         What                                    Who
#==============================================================
# 2002/06/13    First time to run this program
#               The only backup files are MySQL and CGI VBird
#==============================================================
# 0. Get the date messages and backup directory
day=`date +%Y-%m-%d`
backup_dir="/home/scn/disk2/backup/weekly"

#!欲備份的目錄
dir1="/var/www/html/sfs3"
#dir2="/var/lib/mysql/sfs3"

#!備份後的檔名
targetfile1="sfs3html-"`date '+%y-%m-%d'`.tar.gz
#targetfile2="sfs3data-"`date '+%y-%m-%d'`.tar.gz

#!執行tar打包
tar zcvf $backup_dir/$targetfile1 $dir1
#tar zcvf $backup_dir/$targetfile2 $dir2

#!mysql資料庫資訊
#databasename="sfs3"
#rootpassword="scl0380"

#!sql匯出後的檔名
#sqlfilename="sfs3sql-"`date '+%y-%m-%d'`.sql

#!以root身份利用mysqldump指令匯出sfs3資料庫資料
#mysqldump $databasename > $backup_dir/$sqlfilename -uroot -p$rootpassword

#!zip壓縮匯出檔

#zip $backup_dir/$sqlfilename.zip $backup_dir/$sqlfilename

#!只保留zip檔請執行下列指令 不刪除請保留#
#rm -rf $backup_dir/$sqlfilename


#!切換到存放目錄
cd $backup_dir


#!設定ftp帳號密碼與存放目錄
host="172.16.0.2"
user="administrator"
password="nt6908"
replace_dir="weekly"


#!啟動ftp連接

ftp -in << EOF
open $host
user $user $password
cd $replace_dir
bin
put $targetfile1

EOF
發表人: azactam    時間: 2008-10-15 03:27 PM

最近公司在搞資安,小小建議樓主把跟password有關的部份改成****比較安全喔!!




歡迎光臨 TWed2k (http://twed2k.org/) Powered by Discuz! 4.1.0