Nachdem ich den unglaublich weiten Interwebs kein Shell-Script gefunden habe, das mir zusagt (oder das ich mit meinen Wissensstand verstehe) habe ich jetzt selber eines geschrieben. Das war für mich schon eine ziemliche Herausforderung, da ich so gut wie über keine Kenntnisse verfüge.
Da es aber recht gut gelungen ist, dachte ich stelle es mal hier in den Blog, auf das es anderen Hilft.
(Zum Lesen des Scripts den Button drücken)
#! /bin/bash
# Script to backup files by compressing them local and transfer to ftp
# Don’t copy this script in the $BACKUPPATH, it will be deleted at the end of this script. Same goes for the folder itself
# to run this script by a crontab on mondays at 6am type „crontab -e“ and add the line „* 6 * * 1 /root/Scripts/ftp_backup.sh“
# If you change the file path and / or name of this script, change your crontab entry
# Give execute rights by „chmod u+x ftp_backup.sh“
#
# Created by Helge König (HelgeKoenig@GMX.de)
# Mail me for comments or suggestions# Parameters not to change
DATE_VAR=$(date +“%Y%m%d“)# Parameters to change
BACKUPPATH=“/backup“ # path to the local backup folder
SCRIPTPATH=“/root/Scripts“ # path to this script, needed for self backup
SQL_USER=“root“ # SQL root user for DB Backup
SQL_PW=“pw“ # see SQL_USER
FTP_IP=“192.168.0.10″ # IP or Adress for the backup ftp server
FTP_USER=“user“ # Should be self-explaining
FTP_PW=“pw“ # see FTP_USER# check for $BACKUP folder and if fails creating
if [ ! -d $BACKUPPATH ]; then mkdir $BACKUPPATH; fi# Let teh backup beginz!
if [ `whoami` = root ] # check for root user
then {
tar cvz -f $BACKUPPATH/etc_$DATE_VAR.tgz /etc/ # backup of the /etc/ (sub)-folder(s)
tar cvz -f $BACKUPPATH/root-scripts_$DATE_VAR.tgz $SCRIPTPATH # backup of root scripts# change DB_NAME to actual DB name
# don’t forget to change the DB Name in the FTP Backup Section too
mysqldump –user=$SQL_USER –password=$SQL_PW „DB_Name“ > „$BACKUPPATH/DB_NAME_$DATE_VAR.sql“
gzip „$BACKUPPATH/DB_NAME_$DATE_VAR.sql“# begin FTP backup
ftp -pinv $FTP_IP <user $FTP_USER $FTP_PW
bin
put $BACKUPPATH/etc_$DATE_VAR.tgz /etc_$DATE_VAR.tgz
put $SCRIPTPATH/root-scripts_$DATE_VAR.tgz /root-scripts_$DATE_VAR.tgz
put $BACKUPPATH/DB_NAME_$DATE_VAR.gz /DB_NAME_$DATE_VAR.tgz
bye
EOFTP# clean $BACKUPPATH
rm -R $BACKUPPATH
}
else echo „This script need root user“; exit;
fi
Schreibe einen Kommentar