incremental Systems dan mysql Backup

Buat file  ” listserver.txt” , isi perbaris dengan ip_address akan diremote, contoh:

192.168.10.2
192.168.10.3

Buat file remote backup.sh

#!/bin/sh
# backup.sh
# incremental System + MySQL Backup Script v.0.2
# server backup get data from server client
# April 2015 Sigit Afandhi
rm -rf hasil.txt

####Target File
FILE1=”/etc”
FILE2=”/home”
FILE3=”/srv”
FILE4=”/root”
FILE5=”/srv”
FILE6=”/opt”
FILE7=”/var/www”
FILE8=”/var/lib/mysql”

####Other stuff ###
EMAILID=”kamu@emailmu.com”
FILE_BACKUP=”/DATA/BACKUP/*/”

####Time
NOW=$(date +%Y%m%d)

########## Check if user is root ###
if [ $(id -u) != “0” ]; then
echo “error: user id harus root, jika belum silahkan sudo su – !”
exit 1
fi
clear
stty erase ‘^?’

####Read Server Target And Starting Backup
for host_target in $(cat listserver.txt)
do

####Create Folder Backup
echo -e “\033[31;1;35m [+] Create Folder Backup … \033[0m”
ssh $USER@$host_target “hostname -f” > output.txt
FOLDER_PENYIMPANAN=”/DATA/BACKUP/$NOW/$(cat output.txt)/”

mkdir -p $FOLDER_PENYIMPANAN && chmod 777 $FOLDER_PENYIMPANAN
echo -e “\033[31;1;35m [+] Folder Backup on : $FOLDER_PENYIMPANAN  \033[0m”
echo

####Get File Backup
START=$(date +%s)
echo -e “\033[31;1;35m [!] Get File Backup $host_target … \033[0m”
ssh $USER@$host_target “crontab -l” > $FOLDER_PENYIMPANAN/crontab.txt &&
rsync -av $USER@$host_target:$FILE1 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE2 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE3 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE4 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE5 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE6 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE7 $FOLDER_PENYIMPANAN &&
rsync -av $USER@$host_target:$FILE8 $FOLDER_PENYIMPANAN
echo -e “\033[31;1;35m [+] Backup … Done \033[0m”
echo “”
FINISH=$(date +%s)

####Create Report Backup
echo ” ================= $(cat output.txt) : ” >> hasil.txt
echo “Ip Address     : $host_target ” >> hasil.txt
echo “Tanggal Backup : $(date)” >> hasil.txt
echo “Lama Backup    : $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds” >> hasil.txt
echo “File On        : $FOLDER_PENYIMPANAN” >> hasil.txt
echo ” ===================================== ” >> hasil.txt
echo “” >> hasil.txt
rm -rf output.txt
done

####LIST FILE BACKUP
echo ” ================= LIST BACKUP ============= ” >> hasil.txt
ls -al $FILE_BACKUP >> hasil.txt

####Sending Report Backup
mail  -s “Report Backup Server” “$EMAILID” < hasil.txt

,

Leave a Reply