33 lines
844 B
Bash
33 lines
844 B
Bash
#!/bin/bash
|
|
|
|
#backup.sh /var/www/lfbackend OPTION
|
|
#OPTION
|
|
# - F FULL BACKUP
|
|
# - T Only save images from today
|
|
# - I Incremental Backup (Not implemented yet)
|
|
# (OPTIONS T and I only apply for images)
|
|
|
|
#CRON
|
|
#17 * * * * root cd /tmp && /var/www/lfbackend/backup.sh /var/www/lfbackend T
|
|
#45 5 * * * root cd /tmp && /var/www/lfbackend/backup.sh /var/www/lfbackend F
|
|
|
|
OPTION=$2
|
|
|
|
source $1/.env
|
|
|
|
TS=`date +%Y%m%d%H%M%S`
|
|
|
|
mysqldump -u $DB_USERNAME -p$DB_PASSWORD -h $DB_HOST $DB_DATABASE > database.sql
|
|
if [ "$OPTION" == "T" ]
|
|
then
|
|
tar -N "`date +%Y-%m-%d`" -zcvf images.tar.gz -C $1/public/staticimages/ .
|
|
elif [ "$OPTION" == "I" ]
|
|
then
|
|
tar -zcvf images.tar.gz -C $1/public/staticimages/ .
|
|
else
|
|
tar -zcvf images.tar.gz -C $1/public/staticimages/ .
|
|
fi
|
|
|
|
gzip -f database.sql
|
|
tar -cvf backup_${TS}_${OPTION}.tar database.sql.gz images.tar.gz
|
|
|