Confixx: Difference between revisions
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
<pre> | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
# | ######################################################### | ||
# confixx backup | # # | ||
# | # confixx backup # | ||
# # | |||
######################################################### | |||
# | # ------------------- variables ------------------- | ||
HOMEDIR="$(pwd)" | HOMEDIR="$(pwd)" | ||
FILESDIR="$HOMEDIR/files" | FILESDIR="$HOMEDIR/files" | ||
Line 21: | Line 23: | ||
DATESTAMP="$(date "+%F %T")" | DATESTAMP="$(date "+%F %T")" | ||
MySQL_USER=" | MySQL_USER="web389" | ||
MySQL_PASS=" | MySQL_PASS="BXFTHRjd" | ||
MySQL_HOST="localhost" | MySQL_HOST="localhost" | ||
MySQL_ignoredb="information_schema" | |||
# | # ------------------ append log file ---------------- | ||
touch $LOGFILE | touch $LOGFILE | ||
echo "$DATESTAMP | echo "$DATESTAMP starting backup" >> $LOGFILE | ||
# remove old backup | # ----------------- remove old backup -------------- | ||
mkdir $FILESDIR/backup | mkdir $FILESDIR/backup | ||
cd $FILESDIR/backup | cd $FILESDIR/backup | ||
Line 40: | Line 41: | ||
rm * | rm * | ||
# list databases | # ------------------- list databases --------------- | ||
DBS="$(mysql -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS -Bse 'show databases')" | DBS="$(mysql -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS -Bse 'show databases')" | ||
echo "$DATESTAMP -> list databases" >> $LOGFILE | echo "$DATESTAMP -> list databases" >> $LOGFILE | ||
echo "$DBS" > $FILESDIR/backup_tmp/databases.list | echo "$DBS" > $FILESDIR/backup_tmp/databases.list | ||
# ------------------- dump databases --------------- | |||
# dump databases | |||
echo "$DATESTAMP -> dumping databases" >> $LOGFILE | echo "$DATESTAMP -> dumping databases" >> $LOGFILE | ||
for db in $DBS | for db in $DBS | ||
do | do | ||
if [ "$db" != "$MySQL_ignoredb" ]; | |||
then | |||
echo "$DATESTAMP -> dumping database $db" >> $LOGFILE | echo "$DATESTAMP -> dumping database: $db" >> $LOGFILE | ||
mysqldump -u $MySQL_USER -h $MySQL_HOST -p$MySQL_PASS $db > $FILESDIR/backup_tmp/ | 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 | 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 | |||
tar --recursion -czf $FILESDIR/backup/html-$(date +%F).tar.gz -C "$HOMEDIR/html/" * | |||
# --------------- final logfile comment ---------- | |||
echo "$DATESTAMP backup finished" >> $LOGFILE | |||
echo "" >> $LOGFILE | |||
</pre> | </pre> | ||
</blockquote> | </blockquote> |
Revision as of 21:31, 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="web389" MySQL_PASS="BXFTHRjd" 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 tar --recursion -czf $FILESDIR/backup/html-$(date +%F).tar.gz -C "$HOMEDIR/html/" * # --------------- final logfile comment ---------- echo "$DATESTAMP backup finished" >> $LOGFILE echo "" >> $LOGFILE