Confixx: Difference between revisions
No edit summary |
No edit summary |
||
Line 59: | Line 59: | ||
# ------------ compressing database dumps ---------- | # ------------ compressing database dumps ---------- | ||
echo "$DATESTAMP -> compressing database dumps" >> $LOGFILE | echo "$DATESTAMP -> compressing database dumps" >> $LOGFILE | ||
tar -czf $FILESDIR/backup/mysql-$(date +%F).tar.gz -C | tar -czf $FILESDIR/backup/mysql-$(date +%F).tar.gz -C $FILESDIR/backup_tmp/ * | ||
# ------------------- delete dumps ---------------- | # ------------------- delete dumps ---------------- | ||
Line 69: | Line 69: | ||
# -------------- compressing html folder ---------- | # -------------- compressing html folder ---------- | ||
echo "$DATESTAMP -> compressing html files" >> $LOGFILE | echo "$DATESTAMP -> compressing html files" >> $LOGFILE | ||
tar | cd $HOMEDIR/html | ||
tar -czf $FILESDIR/backup/html-$(date +%F).tar.gz * | |||
# --------------- final logfile comment ---------- | # --------------- final logfile comment ---------- |
Latest revision as of 22:15, 17 November 2012
- backup via crontab
- create crontab
20 3 * * * /var/www/$USER$/files/backup.sh >& /dev/null
- backup script
#!/bin/bash ######################################################### # # # confixx backup # # # ######################################################### # ------------------- variables ------------------- HOMEDIR="$(pwd)" FILESDIR="$HOMEDIR/files" LOGFILE="$FILESDIR/backup.log" DATESTAMP="$(date "+%F %T")" MySQL_USER="..." MySQL_PASS="..." MySQL_HOST="localhost" MySQL_ignoredb="information_schema" # ------------------ append log file ---------------- touch $LOGFILE echo "$DATESTAMP starting backup" >> $LOGFILE # ----------------- remove old backup -------------- mkdir $FILESDIR/backup cd $FILESDIR/backup rm * mkdir $FILESDIR/backup_tmp cd $FILESDIR/backup_tmp rm * # ------------------- list databases --------------- DBS="$(mysql -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS -Bse 'show databases')" echo "$DATESTAMP -> list databases" >> $LOGFILE echo "$DBS" > $FILESDIR/backup_tmp/databases.list # ------------------- dump databases --------------- echo "$DATESTAMP -> dumping databases" >> $LOGFILE for db in $DBS do if [ "$db" != "$MySQL_ignoredb" ]; then echo "$DATESTAMP -> dumping database: $db" >> $LOGFILE mysqldump --add-drop-table --allow-keywords -q -c -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS $db > $FILESDIR/backup_tmp/mysql-$db.sql fi done # ------------ compressing database dumps ---------- echo "$DATESTAMP -> compressing database dumps" >> $LOGFILE tar -czf $FILESDIR/backup/mysql-$(date +%F).tar.gz -C $FILESDIR/backup_tmp/ * # ------------------- delete dumps ---------------- echo "$DATESTAMP -> deleting database dumps" >> $LOGFILE mkdir $FILESDIR/backup_tmp cd $FILESDIR/backup_tmp rm * # -------------- compressing html folder ---------- echo "$DATESTAMP -> compressing html files" >> $LOGFILE cd $HOMEDIR/html tar -czf $FILESDIR/backup/html-$(date +%F).tar.gz * # --------------- final logfile comment ---------- echo "$DATESTAMP backup finished" >> $LOGFILE echo "" >> $LOGFILE