Commit c5b086d1 authored by Mikaël Salson's avatar Mikaël Salson

server/backup{,-remote}.sh: Create a SQL backup of the database.

See #2762
parent 437e62bb
Pipeline #20276 failed with stages
in 51 seconds
......@@ -7,9 +7,10 @@ DIR_BACKUP=/mnt/data/backup/vidjil/
# Remote server
ARCHIVE_DIR=/mnt/data/tmp
DATABASE_NAME=vidjil_bak
options=$1
filename=$(ssh ${VIDJIL_SERVER} "cd /home/vidjil/server; . /home/vidjil/virtualenv/bin/activate; sh ./backup.sh ${options} ${ARCHIVE_DIR}" | tail -1)
filename=$(ssh ${VIDJIL_SERVER} "cd /home/vidjil/server; . /home/vidjil/virtualenv/bin/activate; sh ./backup.sh ${options} ${DATABASE_NAME} ${ARCHIVE_DIR}" | tail -1)
scp ${VIDJIL_SERVER}:${filename} ${DIR_BACKUP}
ssh ${VIDJIL_SERVER} "rm -f ${filename}"
......@@ -3,14 +3,19 @@
COMPLETE=0
INCREMENTAL=0
DIR=
DATABASE=
if [ $# -ge 1 -a "$1" = "-h" ]; then
echo "$0: [-c] [-i] [path]
usage() {
echo "$0: [-c] [-i] dbname [path]
-c: Backup everything
-i: Incremental backup, since the first of the month
path: Where to save the file" >&2
exit 1
}
if [ $# -ge 1 -a "$1" = "-h" ]; then
usage
fi
if [ $# -ge 1 -a "$1" = "-i" ]; then
......@@ -23,6 +28,13 @@ if [ $# -ge 1 -a "$1" = "-c" ]; then
shift
fi
if [ $# -eq 0 ]; then
usage
fi
DATABASE="$1"
shift
if [ $# -ge 1 ]; then
DIR="$1/"
fi
......@@ -32,6 +44,7 @@ FIRST_OF_THE_MONTH=$(date --date="$(date +%Y-%m-01)" +"%Y-%m-%d")
vidjil_path=web2py/applications/vidjil
db_backup_file=/tmp/db-backup-$now.csv
sql_backup_file=/tmp/db-backup-$now.sql
defs_py=$vidjil_path/modules/defs.py
......@@ -44,22 +57,23 @@ DIR_SEQUENCES=$(sed -rn "s/^DIR_SEQUENCES.*['\"](.*)['\"].*$/\1/p" $defs_py)
DIR_RESULTS=$(sed -rn "s/^DIR_RESULTS.*['\"](.*)['\"].*$/\1/p" $defs_py)
python web2py/web2py.py -S vidjil -M -R "applications/vidjil/scripts/backup-db.py" -A "$db_backup_file"
mysqldump --no-create-info --complete-insert "$DATABASE" > $sql_backup_file
if [ $COMPLETE -eq 1 ]; then
filename_raw="${DIR}backup_"$now
filename=$filename_raw.zip
zip -r $filename_raw web2py/applications/vidjil/databases/ "$DIR_SEQUENCES" "$DIR_RESULTS" $db_backup_file
zip -r $filename_raw web2py/applications/vidjil/databases/ "$DIR_SEQUENCES" "$DIR_RESULTS" $db_backup_file $sql_backup_file
else
if [ $INCREMENTAL -eq 1 ]; then
filename_raw="${DIR}backup_incremental_${FIRST_OF_THE_MONTH}__${now}.tar"
filename=$filename_raw.gz
tar cvf $filename_raw --force-local web2py/applications/vidjil/databases/ # $db_backup_file
tar cvf $filename_raw --force-local web2py/applications/vidjil/databases/ $db_backup_file $sql_backup_file
tar rvf $filename_raw --force-local --after-date "$FIRST_OF_THE_MONTH" "$DIR_RESULTS" 2>&1 | grep -v "file is unchanged"
gzip $filename_raw
else
filename_raw="${DIR}backup_essentials_"$now
filename=$filename_raw.zip
zip -r $filename_raw web2py/applications/vidjil/databases/ "$DIR_RESULTS" $db_backup_file
zip -r $filename_raw web2py/applications/vidjil/databases/ "$DIR_RESULTS" $db_backup_file $sql_backup_file
fi
fi
rm -f "$db_backup_file"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment