Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Daily backup historized of mysql databases and www dirs
#!/bin/bash
# DECLARATIONS VARIABLES
mysqldbs=(db1 db2 db3)
wwwdirs=(dir1 dir2 dir3)
nbjours=30
jourtodelete=$((nbjours+1))
# ROTATION ANCIENNES VERSIONS
for (( jour = ${nbjours[*]}; jour > 1; jour-- ))
do
jourprec=$((jour-1))
# SYSTEME
mv /home/sauvegardes/etc.$jourprec.tar.gz /home/sauvegardes/etc.$jour.tar.gz
# MYSQL
for db in ${mysqldbs[*]}
do
mv /home/sauvegardes/mysql_dump/$db.$jourprec.sql.tar.gz /home/sauvegardes/mysql_dump/$db.$jour.sql.tar.gz
done
# WWW
for dir in ${wwwdirs[*]}
do
mv /home/sauvegardes/www/$dir.$jourprec.tar.gz /home/sauvegardes/www/$dir.$jour.tar.gz
done
done
# SUPPRESSION VERSION LA PLUS VIEILLE
# SYSTEME
rm /home/sauvegardes/etc.$jourtodelete.sql.tar.gz
# MYSQL
for db in ${mysqldbs[*]}
do
rm /home/sauvegardes/mysql_dump/$db.$jourtodelete.sql.tar.gz
done
# WWW
for dir in ${wwwdirs[*]}
do
rm /home/sauvegardes/www/$dir.$jourtodelete.tar.gz
done
# GENERATION VERSION DU JOUR
# SYSTEME
tar czf /home/sauvegardes/etc.1.tar.gz /etc
# MYSQL
for db in ${mysqldbs[*]}
do
mysqldump -u root --password=MYSQLROOTPASSWORD $db > /home/sauvegardes/mysql_dump/$db.sql
tar czf /home/sauvegardes/mysql_dump/$db.1.sql.tar.gz /home/sauvegardes/mysql_dump/$db.sql
rm /home/sauvegardes/mysql_dump/$db.sql
done
# WWW
for dir in ${wwwdirs[*]}
do
tar czf /home/sauvegardes/www/$dir.1.tar.gz /var/www/$dir/
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.