Loading...
 

Computer at work

Manual local Backups

/home/xavi/scripts/backup_manual_pentinella.sh
#!/bin/bash ####################################### ### PARAMETERS TO CUSTOMIZE THE SCRIPT ####################################### ### Generic Label for the server ### MLABEL="xavi_pentinella" ### MySQL Server Login Info ### MUSER="mysqluser" MPASS="mysqlpass" MHOST="localhost" ### FTP SERVER Login info ### FTPU="ftpuser" FTPP="ftppass" FTPS="ftpserver" FTPF="./backups/pentinella" NOWD=$(date +"%Y-%m-%d") NOWT=$(date +"%H_%M_%S") ## Some paths defined MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" BAKPATH="/home/xavi/backups_locals" # TODO: make the folliwng paths relative to this one BAK="backup_local_pentinella" TIKIFILESABSPATH="/var/www/tiki_files" # Relative paths to backup folders RBAK1="mysql" RBAK2="tikifiles" RBAK3="serverfiles" RBAK4="homexavifiles" EMAILF="ueb@vhir.org" EMAILT="xavier.depedro@vhir.org" SMTP="servirmta1.ir.vhebron.net" #### End of parameters ####################################### # Base path for backup folders BBAK=$BAKPATH/$BAK/$NOWD # Absolute paths to backup folders (base path + relative path) ABAK1=$BBAK/$RBAK1 ABAK2=$BBAK/$RBAK2 ABAK3=$BBAK/$RBAK3 ABAK4=$BBAK/$RBAK4 # Other variables used GZIP="$(which gzip)" # Relative paths for each log file RLOGF=log-$MLABEL-SUM.$NOWD.txt RLOGF1=log-$MLABEL-$RBAK1.$NOWD.txt RLOGF2=log-$MLABEL-$RBAK2.$NOWD.txt RLOGF3=log-$MLABEL-$RBAK3.$NOWD.txt RLOGF4=log-$MLABEL-$RBAK4.$NOWD.txt # Base log path (set by default to the same base path for backups) BLOGF=$BBAK # Absolute path for log files ALOGF=$BLOGF/$RLOGF ALOGF1=$BLOGF/$RLOGF1 ALOGF2=$BLOGF/$RLOGF2 ALOGF3=$BLOGF/$RLOGF3 ALOGF4=$BLOGF/$RLOGF4 ### These next parts (1) & (2) are related to the removal of previous files in these folders if they exist, and create dirs as needed for new set of periodic backups ### ## (1) To remove all previous backups locally at the server and at the same base backup folder, uncomment the following line #[ ! -d $BAKPATH/$BAK ] && mkdir -p $BAKPATH/$BAK || /bin/rm -f $BAKPATH/$BAK/* ## (2) To avoid removing previous backups from teh same day locally, keep the last part commeted out (with ## just in front of "|| /bin/rm -f ..." ) [ ! -d $ABAK1 ] && mkdir -p $ABAK1 # || /bin/rm -f $ABAK1/* [ ! -d $ABAK2 ] && mkdir -p $ABAK2 # || /bin/rm -f $ABAK2/* [ ! -d $ABAK3 ] && mkdir -p $ABAK3 # || /bin/rm -f $ABAK3/* [ ! -d $ABAK4 ] && mkdir -p $ABAK4 # || /bin/rm -f $ABAK4/* ### [ ! -d "$BAK" ] && mkdir -p "$BAK" ### DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=$ABAK1/$db.$NOWD-$NOWT.gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done ### Backup tikifiles ### #tar -czvf $ABAK2/00-$RBAK2-$MLABEL.$NOWD-$NOWT.tgz $TIKIFILESABSPATH/* > $ALOGF2 ### Backup serverfiles ### tar -czhvf $ABAK3/00-$RBAK3-$MLABEL.$NOWD-$NOWT.tgz /etc/* /root/.luckyBackup/* /root/.local/* /root/.ssh/* /root/.config/* > $ALOGF3 ### Backup home user files ### tar -czhvf $ABAK4/00-$RBAK4-$MLABEL.$NOWD-$NOWT.tgz /home/xavi/scripts/* /home/xavi/.local/* /home/xavi/.config/* /home/xavi/.Skype/* /home/xavi/.luckyBackup/* /home/xavi/.ssh/* /home/xavi/.purple/* > $ALOGF4 ### Send files over ftp ### #lftp -u $FTPU,$FTPP -e "mkdir $FTPF/$NOWD;cd $FTPF/$NOWD; mput $ABAK1/*.gz; mput $ABAK2/*.tgz; mput $ABAK3/*.tgz; quit" $FTPS > $ALOGF cd $ABAK1;ls -lh * > $ALOGF1 # Add a short summary with partial dir sizes and append all partial log files into one ($LOGF) cd $BBAK;du -h $RBAK1 $RBAK2 $RBAK3 $RBAK4 > $ALOGF;echo "" >> $ALOGF;echo "--- $RBAK2 uncompressed: ---------------" >> $ALOGF;du $TIKIFILESABSPATH -h --max-depth=2 >> $ALOGF ### Compress and Send log files ### tar -czvf $ALOGF1.tgz -C $BLOGF $RLOGF1 #tar -czvf $ALOGF2.tgz -C $BLOGF $RLOGF2 tar -czvf $ALOGF3.tgz -C $BLOGF $RLOGF3 tar -czvf $ALOGF4.tgz -C $BLOGF $RLOGF4 #lftp -u $FTPU,$FTPP -e "cd $FTPF/$NOWD; put $ALOGF1.tgz; put $ALOGF2.tgz; put $ALOGF3.tgz; put $ALOGF4.tgz; quit" $FTPS ### Send report through email ### sendemail -f $EMAILF -t $EMAILT -u '[Pentinella Manual Local Backup Report]' -m 'Short report attached' -a $ALOGF -a $ALOGF1 -s $SMTP -o tls=no

Crontab

Crontab for root as of Dec 29th, 2015
#Back In Time system entry, this will be edited by the gui: 0 14 * * 1 /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime --backup-job >/dev/null 2>&1 #Back In Time system entry, this will be edited by the gui: 0 14 * * * /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime --profile-id 2 --backup-job >/dev/null 2>&1 30 13 * * Wed sh '/home/xavi/scripts/backup_manual_pentinella.sh' #10 12 * * * cd /var/www/html/12.x/;php console.php index:rebuild > /dev/null 2>&1 # Sending "Daily reports" of watch-emails #* * * * * cd /var/www/html/12.x/;php console.php daily-report:send > /dev/null 2>&1



Alias names for this page: Pentinella

Image Seed: noun \ˈsēd\ : the beginning of something which continues to develop or grow

Knowledge seeds

Switch Language