#!/bin/bash
# get now date and set date path,datetime
_DATEPATH=$(date +%Y-%m-%d)
# set backup base path must end of "/"
_BASEPATH="/data/backup/"
# set log path
_LOGFILE=${_BASEPATH}"log.txt"
# set some path
_SITEDATA=${_BASEPATH}"siteData/"${_DATEPATH}
_SITEAPP=${_BASEPATH}"siteApp/"${_DATEPATH}
_SITEDB=${_BASEPATH}"siteDb/"${_DATEPATH}
_SITEMYSQL=${_BASEPATH}"siteMysql/"${_DATEPATH}
# set host address
_HOSTA = '192.168.10.100';
_HOSTB = '192.168.10.200';
#check base dir
if [ ! -d $_BASEPATH ];then
mkdir -p $_BASEPATH
fi
#check log file
if [ ! -f $_LOGFILE ];then
touch $_LOGFILE
fi
#create base dir
mkdir -p $_SITEDATA
mkdir -p $_SITEAPP
mkdir -p $_SITEDB
mkdir -p $_SITEMYSQL
#fun
function writeLog()
{
echo $1 >> $_LOGFILE
return 1
}
#run
function run()
{
#backup begin
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] ------------------BACKUP Start"
#begin
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy data dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/www-data $_SITEDATA >> $_LOGFILE
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy app dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/www-cmsapp $_SITEAPP >> $_LOGFILE
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy db dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/www-sql $_SITEDB >> $_LOGFILE
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy mysql dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/usr/local/mysql/ $_SITEMYSQL >> $_LOGFILE
# end
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] ------------------BACKUP End"
}
run();
# get now date and set date path,datetime
_DATEPATH=$(date +%Y-%m-%d)
# set backup base path must end of "/"
_BASEPATH="/data/backup/"
# set log path
_LOGFILE=${_BASEPATH}"log.txt"
# set some path
_SITEDATA=${_BASEPATH}"siteData/"${_DATEPATH}
_SITEAPP=${_BASEPATH}"siteApp/"${_DATEPATH}
_SITEDB=${_BASEPATH}"siteDb/"${_DATEPATH}
_SITEMYSQL=${_BASEPATH}"siteMysql/"${_DATEPATH}
# set host address
_HOSTA = '192.168.10.100';
_HOSTB = '192.168.10.200';
#check base dir
if [ ! -d $_BASEPATH ];then
mkdir -p $_BASEPATH
fi
#check log file
if [ ! -f $_LOGFILE ];then
touch $_LOGFILE
fi
#create base dir
mkdir -p $_SITEDATA
mkdir -p $_SITEAPP
mkdir -p $_SITEDB
mkdir -p $_SITEMYSQL
#fun
function writeLog()
{
echo $1 >> $_LOGFILE
return 1
}
#run
function run()
{
#backup begin
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] ------------------BACKUP Start"
#begin
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy data dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/www-data $_SITEDATA >> $_LOGFILE
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy app dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/www-cmsapp $_SITEAPP >> $_LOGFILE
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy db dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/www-sql $_SITEDB >> $_LOGFILE
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] Copy mysql dir : HOST $_HOSTA to HOST $_HOSTB"
scp -r -4 -B root@$_HOSTA:/usr/local/mysql/ $_SITEMYSQL >> $_LOGFILE
# end
writeLog "["$(date +%Y-%m-%d-%H-%M-%S)"] ------------------BACKUP End"
}
run();