services/codimd/run

48 lines
1.2 KiB
Plaintext
Raw Normal View History

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"
echo "./run restore : Restoration de la sauvegarde de Codimd"
}
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
docker run -it --rm -v $HOME/backups/${CODIMD_DOMAIN}:/backup --volumes-from codimd alpine:3.11.6 ash -c "cd config && tar cvf /backup/${BACKUP_DATE}_${CODIMD_DOMAIN}_config.tar ."
}
codimd_restore() {
script_env
postgres_restore
docker run -it --rm -v $HOME/backups/${CODIMD_DOMAIN}:/backup --volumes-from codimd alpine:3.11.6 ash -c "cd /config && tar xvf /backup/${BACKUP_DATE}_${CODIMD_DOMAIN}_config.tar --strip 1"
}
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