Last active
August 3, 2020 16:05
-
-
Save benchonaut/bc360a9a99dd8c8ddd62ee4a789e5d43 to your computer and use it in GitHub Desktop.
Backup domain folders, their respective mysql db and their mongodb collection
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 | |
##LOAD .profile in case of cron | |
. ~/.profile | |
##INIT BASICS | |
. ~/.backupdomains.conf ## LOAD CONFIG FROM FILE | |
####################################### | |
##~/.backupdomains.conf should contain | |
#| BACKUP_DEST=~/backup/ | |
#| DOMAINS=/domains | |
### and if you want do mongodump collections as well | |
#| CONFIGTABLE=system_settings | |
#| CONFIGITEM=blabla_database_settings | |
#| OCTOBERONLY=true | |
###BACKUP ONLY OCTOBERCMS FILES | |
#| KEEPDAYS=7 | |
###( backup older than 7 days will be deleted , defaults to 7) | |
#| INTERVAL=12 | |
### BACKUP INTERVAL IN HOURS ( 168 for 1 week, 5124 for ~1 month) | |
### DEFAULT INTERVAL IS 24H | |
####################################### | |
### | |
### | |
#the .env files need smth like | |
#|DB_USERNAME=user | |
#|DB_CONNECTION=mysql | |
MONGODUMP=$(which mongodump || echo "NO MONGODUMP") | |
MYSQLDUMP=$(which mysqldump || (echo "INSTALL MYSQLDUMP!";exit 1)) | |
TIMESTAMP=$(date -u +%Y-%m-%d-%H-%M) | |
test -e $BACKUP_DEST || (echo "NO BACKUP DIR" ; mkdir $BACKUP_DEST) | |
mkdir -p $BACKUP_DEST/$TIMESTAMP | |
newest=$(for i in $(find $BACKUP_DEST/ -type f -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" );do date -u +%s -r $i;done|sort -n|tail -n1); | |
if [[ -z $newest ]];then newest=666666 ; fi | |
age_newest_hours=$( expr $(expr $(date -u +%s) - $newest ) / 60 / 60 ); age_newest_days=$(expr $age_newest_hours / 24 ); | |
if [ -z $INTERVAL ];then INTERVAL=24 ; fi | |
if [ -z $KEEPDAYS ];then KEEPDAYS=7 ; fi | |
echo $INTERVAL "@" $newest "->" $age_newest_hours | |
if [ "$age_newest_hours" -ge "$INTERVAL" ] ; then | |
echo "Kosmoskosmos custom backup 0.0.0.1 - Saving "$DOMAINS" to "$BACKUP_DEST" with "$MONGODUMP" and "$MYSQLDUMP | |
find $DOMAINS/ -maxdepth 1 -not \( -path $DOMAINS"/*experimental" -prune \) -type d |grep -v -e $DOMAINS/"$" | while read DOMAINDIR ; do | |
if [ "$NO_DOCROOT" == "true" ]; then | |
echo "NOT SAVING DOCROOT because NO_DOCROOT is true" | |
else | |
echo -ne "→→SAVING DOMAIN DIRECTORY $DOMAINDIR→\t"; | |
DOMAINALIAS=${DOMAINDIR/$DOMAINS/} | |
if [ "$OCTOBER_ONLY" == "true" ]; then | |
tar czf $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS".tar.gz" $(find $DOMAINDIR/{live,test}/{themes,storage}/ -maxdepth 1 -mindepth 1 -not -path "*storage/temp" -not -path "*storage/logs" -not -path "*storage/session" -not -path "*storage/cache" 2>/dev/null) 2>/dev/null ; | |
else | |
tar czf $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS".tar.gz" $DOMAINDIR/ 2>/dev/null ; | |
fi | |
fi | |
find $DOMAINDIR -name "\.env" -type f -exec dirname {} \; |while read dir ;do | |
envfile=$dir/.env ; | |
echo -n "$dir described by $envfile →" ; | |
##GET DB CREDENTIALS | |
{ | |
DBCON=$(grep ^DB_CONNECTION $envfile || echo DB_CONNECTION=mysql);DBCON=$(echo $DBCON|cut -d= -f2); | |
DBNAM=$(grep ^DB_DATABASE $envfile );DBNAM=$(echo $DBNAM|cut -d= -f2); | |
DBUSR=$(grep ^DB_USERNAME $envfile );DBUSR=$(echo $DBUSR|cut -d= -f2); | |
DBPAS=$(grep ^DB_PASSWORD $envfile );DBPAS=$(echo $DBPAS|cut -d= -f2); | |
if [[ ! -z $DBCON ]] && [[ ! -z $DBNAM ]] && [[ ! -z $DBPAS ]] && [[ ! -z $DBUSR ]];then | |
$MYSQLDUMP -u$DBNAM -p$DBPAS $DBNAM --single-transaction > $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MYSQL-"$DBNAM".tar.gz " 2>/dev/null | |
###GET MONGO Collection | |
MONGODB=$(mysql -u$DBUSR -p$DBPAS --batch --silent -e "select value from $CONFIGTABLE where item = '$CONFIGITEM' ;" --database=$DBNAM 2>/dev/null |sed 's/","/",\n"/g'|grep database|cut -d\" -f4) | |
if [[ ! -z $MONGODB ]];then | |
echo -n " "$MONGODB" " | |
#mongodump --db $MONGODB -collection $MONGOCOL --out | |
mongodump --quiet --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
else | |
echo -n " NO MONGODB " | |
fi | |
else | |
echo -n " NO DB CONFIGURED IN .env " | |
fi | |
} | |
done ; echo DONE ; | |
done | |
echo -n "→→SAVING LETSENCRYPT" ; | |
test -d /etc/letsencrypt && tar czf $BACKUP_DEST/$TIMESTAMP/letsencrypt.tar.gz /etc/letsencrypt | |
find $BACKUP_DEST/$TIMESTAMP/ -type f -exec md5sum {} \; > $BACKUP_DEST/$TIMESTAMP/md5sum | |
tar czf $BACKUP_DEST/$TIMESTAMP.tgz $BACKUP_DEST/$TIMESTAMP | |
find $BACKUP_DEST/$TIMESTAMP -delete | |
fi | |
if [[ ! -z $KEEPDAYS ]];then | |
find $BACKUP_DEST/ -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" -mtime +$KEEPDAYS -delete; | |
fi | |
find $BACKUP_DEST/$TIMESTAMP -empty -delete | |
echo FINISHED |
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 | |
##LOAD .profile in case of cron | |
. ~/.profile | |
##INIT BASICS | |
. ~/.backupdomains.conf ## LOAD CONFIG FROM FILE | |
####################################### | |
##~/.backupdomains.conf should contain | |
#| BACKUP_DEST=~/backup/ | |
#| DOMAINS=/domains | |
### and if you want do mongodump collections as well | |
#| CONFIGTABLE=system_settings | |
#| CONFIGITEM=blabla_database_settings | |
#| OCTOBERONLY=true | |
###BACKUP ONLY OCTOBERCMS FILES | |
#| KEEPDAYS=7 | |
###( backup older than 7 days will be deleted , defaults to 7) | |
#| INTERVAL=12 | |
### BACKUP INTERVAL IN HOURS ( 168 for 1 week, 5124 for ~1 month) | |
### DEFAULT INTERVAL IS 24H | |
####################################### | |
### | |
### | |
#the .env files need smth like | |
#|DB_USERNAME=user | |
#|DB_CONNECTION=mysql | |
MONGODUMP=$(which mongodump || echo "NO MONGODUMP") | |
MYSQLDUMP=$(which mysqldump || (echo "INSTALL MYSQLDUMP!";exit 1)) | |
TIMESTAMP=$(date -u +%Y-%m-%d-%H-%M) | |
test -e $BACKUP_DEST || (echo "NO BACKUP DIR" ; mkdir $BACKUP_DEST) | |
mkdir -p $BACKUP_DEST/$TIMESTAMP | |
newest=$(for i in $(find $BACKUP_DEST/ -type f -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" );do date -u +%s -r $i;done|sort -n|tail -n1); | |
if [[ -z $newest ]];then newest=666666 ; fi | |
age_newest_hours=$( expr $(expr $(date -u +%s) - $newest ) / 60 / 60 ); age_newest_days=$(expr $age_newest_hours / 24 ); | |
if [ -z $INTERVAL ];then INTERVAL=24 ; fi | |
if [ -z $KEEPDAYS ];then KEEPDAYS=7 ; fi | |
echo $INTERVAL "@" $newest "->" $age_newest_hours | |
if [ "$age_newest_hours" -ge "$INTERVAL" ] ; then | |
echo "custom backup 0.0.0.1 - Saving "$DOMAINS" to "$BACKUP_DEST" with "$MONGODUMP" and "$MYSQLDUMP | |
find $DOMAINS/ -maxdepth 1 -not \( -path $DOMAINS"/*experimental" -prune \) -type d |grep -v -e $DOMAINS/"$" | while read DOMAINDIR ; do | |
if [ "$NO_DOCROOT" == "true" ]; then | |
DOMAINALIAS=${DOMAINDIR/$DOMAINS/} | |
echo "NOT SAVING $(basename $DOMAINALIAS) DOCROOT because NO_DOCROOT is true" | |
else | |
echo -ne "→→SAVING DOMAIN DIRECTORY $DOMAINDIR→\t"; | |
DOMAINALIAS=${DOMAINDIR/$DOMAINS/} | |
if [ "$OCTOBER_ONLY" == "true" ]; then | |
tar czf $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS".tar.gz" $(find $DOMAINDIR/{live,test}/{themes,storage}/ -maxdepth 1 -mindepth 1 -not -path "*storage/temp" -not -path "*storage/logs" -not -path "*storage/session" -not -path "*storage/cache" 2>/dev/null) 2>/dev/null ; | |
else | |
tar czf $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS".tar.gz" $DOMAINDIR/ 2>/dev/null ; | |
fi | |
fi | |
find $DOMAINDIR -name "\.env" -type f -exec dirname {} \; |while read dir ;do | |
envfile=$dir/.env ; | |
echo -n "$dir described by $envfile →" ; | |
##GET DB CREDENTIALS | |
{ | |
DBCON=$(grep ^DB_CONNECTION $envfile || echo DB_CONNECTION=mysql);DBCON=$(echo $DBCON|cut -d= -f2); | |
DBNAM=$(grep ^DB_DATABASE $envfile );DBNAM=$(echo $DBNAM|cut -d= -f2); | |
DBUSR=$(grep ^DB_USERNAME $envfile );DBUSR=$(echo $DBUSR|cut -d= -f2); | |
DBPAS=$(grep ^DB_PASSWORD $envfile );DBPAS=$(echo $DBPAS|cut -d= -f2); | |
if [[ ! -z $DBCON ]] && [[ ! -z $DBNAM ]] && [[ ! -z $DBPAS ]] && [[ ! -z $DBUSR ]];then | |
echo " MYSQL: " | |
$MYSQLDUMP -u$DBUSR -p$DBPAS $DBNAM --single-transaction > $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MYSQL-"$DBNAM".sql" | |
#ls -lh1 $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MYSQL-"$DBNAM".sql" | |
###GET MONGO Collection | |
MONGODB=$(mysql -u$DBUSR -p$DBPAS --batch --silent -e "select value from $CONFIGTABLE where item = '$CONFIGITEM' ;" --database=$DBNAM 2>/dev/null |sed 's/","/",\n"/g'|grep database|cut -d\" -f4) | |
if [[ ! -z $MONGODB ]];then | |
echo -n " MONGO: "$MONGODB" →$BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS " | |
#mongodump --db $MONGODB -collection $MONGOCOL --out | |
# mongodump --quiet --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
mongodump --quiet -u $DBUSR -p$DBPAS --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
#ls -lh1 $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
else | |
echo -n " NO MONGODB " | |
fi | |
else | |
echo -n " NO DB CONFIGURED IN .env " | |
fi | |
} | |
done ; echo DONE ; | |
done | |
echo -n "→→SAVING LETSENCRYPT" ; | |
test -d /etc/letsencrypt && tar czf $BACKUP_DEST/$TIMESTAMP/letsencrypt.tar.gz /etc/letsencrypt | |
find $BACKUP_DEST/$TIMESTAMP/ -type f -exec md5sum {} \; > $BACKUP_DEST/$TIMESTAMP/md5sum | |
tar czf $BACKUP_DEST/$TIMESTAMP.tgz $BACKUP_DEST/$TIMESTAMP | |
find $BACKUP_DEST/$TIMESTAMP -delete | |
du -h -s $BACKUP_DEST/$TIMESTAMP.tgz | |
fi | |
if [[ ! -z $KEEPDAYS ]];then | |
find $BACKUP_DEST/ -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" -mtime +$KEEPDAYS -delete; | |
fi | |
find $BACKUP_DEST/$TIMESTAMP -type d -delete | |
echo FINISHED |
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 | |
##LOAD .profile in case of cron | |
. ~/.profile | |
##INIT BASICS | |
. ~/.backupdomains.conf ## LOAD CONFIG FROM FILE | |
####################################### | |
##~/.backupdomains.conf should contain | |
#| BACKUP_DEST=~/backup/ | |
#| DOMAINS=/domains | |
### and if you want do mongodump collections as well | |
#| CONFIGTABLE=system_settings | |
#| CONFIGITEM=blabla_database_settings | |
#| OCTOBERONLY=true | |
###BACKUP ONLY OCTOBERCMS FILES | |
#| KEEPDAYS=7 | |
###( backup older than 7 days will be deleted , defaults to 7) | |
#| INTERVAL=12 | |
### BACKUP INTERVAL IN HOURS ( 168 for 1 week, 5124 for ~1 month) | |
### DEFAULT INTERVAL IS 24H | |
####################################### | |
### | |
### | |
#the .env files need smth like | |
#|DB_USERNAME=user | |
#|DB_CONNECTION=mysql | |
MONGODUMP=$(which mongodump || echo "NO MONGODUMP") | |
MYSQLDUMP=$(which mysqldump || (echo "INSTALL MYSQLDUMP!";exit 1)) | |
TIMESTAMP=$(date -u +%Y-%m-%d-%H-%M) | |
test -e $BACKUP_DEST || (echo "NO BACKUP DIR" ; mkdir $BACKUP_DEST) | |
mkdir -p $BACKUP_DEST/$TIMESTAMP | |
newest=$(for i in $(find $BACKUP_DEST/ -type f -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" );do date -u +%s -r $i;done|sort -n|tail -n1); | |
if [[ -z $newest ]];then newest=666666 ; fi | |
age_newest_hours=$( expr $(expr $(date -u +%s) - $newest ) / 60 / 60 ); age_newest_days=$(expr $age_newest_hours / 24 ); | |
if [ -z $INTERVAL ];then INTERVAL=24 ; fi | |
if [ -z $KEEPDAYS ];then KEEPDAYS=7 ; fi | |
echo $INTERVAL "@" $newest "->" $age_newest_hours | |
if [ "$age_newest_hours" -ge "$INTERVAL" ] ; then | |
echo "custom backup 0.0.0.1 - Saving "$DOMAINS" to "$BACKUP_DEST" with "$MONGODUMP" and "$MYSQLDUMP | |
find $DOMAINS/ -maxdepth 1 -not \( -path $DOMAINS"/*experimental" -prune \) -type d |grep -v -e $DOMAINS/"$" | while read DOMAINDIR ; do | |
if [ "$NO_DOCROOT" == "true" ]; then | |
DOMAINALIAS=${DOMAINDIR/$DOMAINS/} | |
echo "NOT SAVING $(basename $DOMAINALIAS) DOCROOT because NO_DOCROOT is true" | |
else | |
echo -ne "→→SAVING DOMAIN DIRECTORY $DOMAINDIR→\t"; | |
DOMAINALIAS=${DOMAINDIR/$DOMAINS/} | |
if [ "$OCTOBER_ONLY" == "true" ]; then | |
tar czf $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS".tar.gz" $(find $DOMAINDIR/{live,test}/{themes,storage}/ -maxdepth 1 -mindepth 1 -not -path "*storage/temp" -not -path "*storage/logs" -not -path "*storage/session" -not -path "*storage/cache" 2>/dev/null) 2>/dev/null ; | |
else | |
tar czf $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS".tar.gz" $DOMAINDIR/ 2>/dev/null ; | |
fi | |
fi | |
find $DOMAINDIR -name "\.env" -type f -exec dirname {} \; |while read dir ;do | |
envfile=$dir/.env ; | |
echo -n "$dir described by $envfile →" ; | |
##GET DB CREDENTIALS | |
{ | |
DBCON=$(grep ^DB_CONNECTION $envfile || echo DB_CONNECTION=mysql);DBCON=$(echo $DBCON|cut -d= -f2); | |
DBNAM=$(grep ^DB_DATABASE $envfile );DBNAM=$(echo $DBNAM|cut -d= -f2); | |
DBUSR=$(grep ^DB_USERNAME $envfile );DBUSR=$(echo $DBUSR|cut -d= -f2); | |
DBPAS=$(grep ^DB_PASSWORD $envfile );DBPAS=$(echo $DBPAS|cut -d= -f2); | |
if [[ ! -z $DBCON ]] && [[ ! -z $DBNAM ]] && [[ ! -z $DBPAS ]] && [[ ! -z $DBUSR ]];then | |
echo " MYSQL: " | |
$MYSQLDUMP -u$DBUSR -p$DBPAS $DBNAM --single-transaction > $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MYSQL-"$DBNAM".sql" | |
#ls -lh1 $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MYSQL-"$DBNAM".sql" | |
###GET MONGO Collection | |
MONGODB=$(mysql -u$DBUSR -p$DBPAS --batch --silent -e "select value from $CONFIGTABLE where item = '$CONFIGITEM' ;" --database=$DBNAM 2>/dev/null |sed 's/","/",\n"/g'|grep database|cut -d\" -f4) | |
if [[ ! -z $MONGODB ]];then | |
echo -n " MONGO: "$MONGODB" →$BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS " | |
#mongodump --db $MONGODB -collection $MONGOCOL --out | |
# mongodump --quiet --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
mongodump --quiet -u $DBUSR -p$DBPAS --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
#ls -lh1 $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
else | |
echo -n " NO MONGODB " | |
fi | |
else | |
echo -n " NO DB CONFIGURED IN .env " | |
fi | |
} | |
done ; echo DONE ; | |
done | |
echo -n "→→SAVING LETSENCRYPT" ; | |
test -d /etc/letsencrypt && tar czf $BACKUP_DEST/$TIMESTAMP/letsencrypt.tar.gz /etc/letsencrypt | |
find $BACKUP_DEST/$TIMESTAMP/ -type f -exec md5sum {} \; > $BACKUP_DEST/$TIMESTAMP/md5sum | |
tar czf $BACKUP_DEST/$TIMESTAMP.tgz $BACKUP_DEST/$TIMESTAMP | |
find $BACKUP_DEST/$TIMESTAMP -delete | |
du -h -s $BACKUP_DEST/$TIMESTAMP.tgz | |
fi | |
if [[ ! -z $KEEPDAYS ]];then | |
find $BACKUP_DEST/ -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" -mtime +$KEEPDAYS -delete; | |
fi | |
find $BACKUP_DEST/$TIMESTAMP -type d -delete | |
echo FINISHED |
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 | |
MYVERSION=0.0.0.2 | |
##LOAD .profile in case of cron | |
. ~/.profile | |
##INIT BASICS | |
. ~/.backupdomains.conf ## LOAD CONFIG FROM FILE | |
####################################### | |
##~/.backupdomains.conf should contain | |
#| BACKUP_DEST=~/backup/ | |
#| DOMAINS=/domains | |
### and if you want do mongodump collections as well | |
#| CONFIGTABLE=system_settings | |
#| CONFIGITEM=blabla_database_settings | |
#| OCTOBERONLY=true | |
###BACKUP ONLY OCTOBERCMS FILES | |
#| KEEPDAYS=7 | |
###( backup older than 7 days will be deleted , defaults to 7) | |
#| INTERVAL=12 | |
### BACKUP INTERVAL IN HOURS ( 168 for 1 week, 5124 for ~1 month) | |
### DEFAULT INTERVAL IS 24H | |
####################################### | |
### | |
### | |
#the .env files need smth like | |
#|DB_USERNAME=user | |
#|DB_CONNECTION=mysql | |
MONGODUMP=$(which mongodump || echo "NO MONGODUMP") | |
MYSQLDUMP=$(which mysqldump || (echo "INSTALL MYSQLDUMP!";exit 1)) | |
TIMESTAMP=$(date -u +%Y-%m-%d-%H-%M) | |
test -e $BACKUP_DEST || (echo "NO BACKUP DIR" ; mkdir $BACKUP_DEST) | |
mkdir -p $BACKUP_DEST/$TIMESTAMP | |
newest=$(for i in $(find $BACKUP_DEST/ -type f -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" );do date -u +%s -r $i;done|sort -n|tail -n1); | |
if [[ -z $newest ]];then newest=666666 ; fi | |
age_newest_hours=$( expr $(expr $(date -u +%s) - $newest ) / 60 / 60 ); age_newest_days=$(expr $age_newest_hours / 24 ); | |
if [ -z $INTERVAL ];then INTERVAL=24 ; fi | |
if [ -z $KEEPDAYS ];then KEEPDAYS=7 ; fi | |
echo $INTERVAL "@" $newest "->" $age_newest_hours | |
if [ "$age_newest_hours" -ge "$INTERVAL" ] ; then | |
echo "custom domain backup "${MYVERSION}" - Saving "$DOMAINS" to "$BACKUP_DEST" with "$MONGODUMP" and "$MYSQLDUMP | |
find $DOMAINS/ -maxdepth 1 -not \( -path $DOMAINS"/*experimental" -prune \) -type d |grep -v -e $DOMAINS/"$" | while read DOMAINDIR ; do | |
if [ "$NO_DOCROOT" == "true" ]; then | |
echo "NOT SAVING DOCROOT because NO_DOCROOT is true" | |
else | |
echo -ne "→→SAVING DOMAIN DIRECTORY $DOMAINDIR→\t"; | |
DOMAINALIAS=${DOMAINDIR/$DOMAINS/} | |
if [ "$OCTOBER_ONLY" == "true" ]; then | |
tar czf $BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}".tar.gz" $(find $DOMAINDIR/{live,test}/{themes,storage}/ -maxdepth 1 -mindepth 1 -not -path "*storage/temp" -not -path "*storage/logs" -not -path "*storage/session" -not -path "*storage/cache" 2>/dev/null) 2>/dev/null ; | |
else | |
tar czf $BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}".tar.gz" $DOMAINDIR/ 2>/dev/null ; | |
fi | |
fi | |
find $DOMAINDIR -name "\.env" -type f -exec dirname {} \; |while read dir ;do | |
envfile=$dir/.env ; | |
echo -n "$dir described by $envfile →" ; | |
DOMAINALIAS=${dir/$DOMAINS/} | |
DOMAINALIAS=${DOMAINALIAS/\//} | |
##GET DB CREDENTIALS | |
{ | |
DBCON=$(grep ^DB_CONNECTION $envfile || echo DB_CONNECTION=mysql);DBCON=$(echo $DBCON|cut -d= -f2); | |
DBNAM=$(grep ^DB_DATABASE $envfile );DBNAM=$(echo $DBNAM|cut -d= -f2); | |
DBUSR=$(grep ^DB_USERNAME $envfile );DBUSR=$(echo $DBUSR|cut -d= -f2); | |
DBPAS=$(grep ^DB_PASSWORD $envfile );DBPAS=$(echo $DBPAS|cut -d= -f2); | |
if [[ ! -z $DBCON ]] && [[ ! -z $DBNAM ]] && [[ ! -z $DBPAS ]] && [[ ! -z $DBUSR ]];then | |
echo "mysqldump -u$DBNAM -p***** $DBNAM to :"$BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}"-MYSQL-"$DBNAM".sql.gz || " | |
$MYSQLDUMP -u$DBUSR -p$DBPAS $DBNAM --single-transaction | gzip --rsyncable > $BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}"-MYSQL-"$DBNAM".sql.gz" | |
ls -lh1 $BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}"-MYSQL-"$DBNAM".sql.gz" | |
###GET MONGO Collection | |
MONGODB=$(mysql -u$DBUSR -p$DBPAS --batch --silent -e "select value from $CONFIGTABLE where item = '$CONFIGITEM' ;" --database=$DBNAM 2>/dev/null |sed 's/","/",\n"/g'|grep database|cut -d\" -f4) | |
if [[ ! -z $MONGODB ]];then | |
echo -n "--quiet -u $DBUSR -p$DBPAS --db $MONGODB to :"$BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}"-MONGODB-"$MONGODB" || " | |
#mongodump --db $MONGODB -collection $MONGOCOL --out | |
#mongodump --quiet --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}"-MONGODB-"$MONGODB ; | |
mongodump --quiet -u $DBUSR -p$DBPAS --db $MONGODB --out $BACKUP_DEST/$TIMESTAMP/$DOMAINALIAS"-MONGODB-"$MONGODB ; | |
ls -lh1 $BACKUP_DEST/$TIMESTAMP/${DOMAINALIAS//\//_}"-MONGODB-"$MONGODB | |
else | |
echo -n " NO MONGODB " | |
fi | |
else | |
echo -n " NO DB CONFIGURED IN .env " | |
fi | |
} | |
done ; echo DONE ; | |
done | |
echo -n "→→SAVING LETSENCRYPT" ; | |
test -d /etc/letsencrypt && tar czf $BACKUP_DEST/$TIMESTAMP/letsencrypt.tar.gz /etc/letsencrypt | |
echo -n md5sum | |
find $BACKUP_DEST/$TIMESTAMP/ -type f -exec md5sum {} \; > $BACKUP_DEST/$TIMESTAMP/md5sum | |
echo -n creating archive | |
tar czf $BACKUP_DEST/$TIMESTAMP.tgz $BACKUP_DEST/$TIMESTAMP &>/dev/null | |
ls -lh1 $BACKUP_DEST/$TIMESTAMP.tgz | |
find $BACKUP_DEST/$TIMESTAMP -delete | |
fi | |
if [[ ! -z $KEEPDAYS ]];then | |
echo deleting from $KEEPDAYS | |
find $BACKUP_DEST/ -name "[1-9][0-9][0-9][0-9]-[0-9][0-9]-*.tgz" -mtime +$KEEPDAYS -delete; | |
fi | |
find $BACKUP_DEST/$TIMESTAMP -empty -delete | |
echo FINISHED |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment