Last active
December 4, 2019 09:52
-
-
Save brunob/ade10244dd3dace7282e85b158779256 to your computer and use it in GitHub Desktop.
backup geodiv v2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Generation des dates | |
date=$(date +%Y%m%d) | |
old=$(date +%Y%m%d -d '8 days ago') | |
### | |
# Pamrametres du script | |
### | |
# Chemin du repertoire de la sauvegarde | |
state="/var/state/"$date | |
# Chemin du backup NFS | |
distant="/home/bb/backup" | |
# Creation des dossiers state et distant, s'ils existent, ignorer | |
mkdir $state 2> /dev/null; | |
mkdir $distant 2> /dev/null; | |
# Prefixe des sauvegardes | |
prefixe="geodiv" | |
# Variables persos | |
host_ftp="ftp.host.net" | |
user_ftp="ftp.login" | |
### | |
# Backup SQL | |
### | |
# Options passees à MysqlDUMP | |
options="--add-drop-table --complete-insert" | |
# On construit la liste des bases de données | |
bases="$(mysql -Bse 'show databases')" | |
# On lance le dump des bases | |
for db in $bases | |
do | |
mysqldump $options $db | gzip > $state"/"$db"-"$date".sql.gz" | |
echo "["$(date +%F\ %X)"] Dump compressé dans "$state"/"$db"-"$date".sql.gz" | |
done | |
### | |
# Fichiers sites | |
### | |
backup_sites=$date"-sites.tar.gz" | |
tar --exclude "*/tmp" --exclude "*/local" -I pigz -cvf $state"/"$backup_sites /var/www/ | |
# autre option pour exclure les caches | |
# tar --exclude-caches -I pigz -cvf $state"/"$backup_sites /var/www/ | |
### | |
# Transfer data | |
### | |
# monter le backup ftp en nfs | |
mount -t nfs ${host_ftp}:/export/ftpbackup/${user_ftp} $distant | |
# envoyer les fichiers de backup sql vers le backup ftp, puis supprimer la plus vieille archive sur le backup et en local | |
#cp -R $state ${distant}/${date} | |
rsync -av --no-o --no-g $state $distant | |
rm -rf $state; | |
rm -rf ${distant}/${old} | |
# synchroniser la copie de /etc/apache2/sites-available avec rsync | |
rsync -av --no-o --no-g --delete /etc/apache2/sites-available ${distant}/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment