2020-06-01 09:34:42 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
. $DIR/../help.sh
|
|
|
|
. $DIR/../postgres/run --only-source
|
|
|
|
|
|
|
|
codimd_help() {
|
|
|
|
echo "./run backup : Lancement de la sauvegarde de Codimd"
|
2021-01-04 11:23:35 +01:00
|
|
|
echo "./run restore : Restauration de la sauvegarde de Codimd"
|
2020-06-01 09:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
codimd_backup() {
|
|
|
|
script_env
|
|
|
|
BACKUP_DATE_DEFAULT=`date +%Y%m%d_%H%M%S`
|
|
|
|
BACKUP_DATE=${BACKUP_DATE:-$BACKUP_DATE_DEFAULT}
|
|
|
|
backup_folder_create
|
|
|
|
|
|
|
|
POSTGRES_BACKUP_FILE=backups/${BACKUP_DATE}_${CODIMD_DOMAIN}_postgres.sql
|
|
|
|
postgres_backup
|
|
|
|
|
2021-01-04 11:22:49 +01:00
|
|
|
docker run -it --rm -v $HOME/backups/${CODIMD_DOMAIN}:/backup --volumes-from codimd alpine:3.12.2 ash -c "cd config && tar cvf /backup/${BACKUP_DATE}_${CODIMD_DOMAIN}_config.tar ."
|
2020-06-01 09:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
codimd_restore() {
|
|
|
|
script_env
|
|
|
|
|
|
|
|
postgres_restore
|
2021-01-04 11:22:49 +01:00
|
|
|
docker run -it --rm -v $HOME/backups/${CODIMD_DOMAIN}:/backup --volumes-from codimd alpine:3.12.2 ash -c "cd /config && tar xvf /backup/${BACKUP_DATE}_${CODIMD_DOMAIN}_config.tar --strip 1"
|
2020-06-01 09:34:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -ge 1 ]; then
|
|
|
|
if [ "${1}" == "backup" ]; then
|
|
|
|
script_start
|
|
|
|
codimd_backup
|
|
|
|
script_end
|
|
|
|
elif [ "${1}" == "restore" ]; then
|
|
|
|
script_start
|
|
|
|
codimd_restore
|
|
|
|
script_end
|
|
|
|
elif [ "${1}" != "--only-source" ]; then
|
|
|
|
codimd_help
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
codimd_help
|
|
|
|
fi
|