services/nextcloud/run

50 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2020-09-03 11:42:35 +02:00
#!/bin/bash
set -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $DIR/../help.sh
. $DIR/../postgres/run --only-source
nextcloud_help() {
echo "./run backup : Lancement de la sauvegarde de Nextcloud"
2021-01-04 11:23:35 +01:00
echo "./run restore : Restauration de la sauvegarde de Nextcloud"
2020-09-03 11:42:35 +02:00
}
nextcloud_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}_${NEXTCLOUD_DOMAIN}_postgres.sql
2021-01-04 11:23:35 +01:00
docker-compose exec --user www-data nextcloud php occ maintenance:mode --on
2020-09-03 11:42:35 +02:00
postgres_backup
2021-01-04 11:30:02 +01:00
docker run -it --rm -v $HOME/backups/${NEXTCLOUD_DOMAIN}:/backup --volumes-from nextcloud alpine:3.12.3 ash -c "cd /var/www/html && tar cvf /backup/${BACKUP_DATE}_${NEXTCLOUD_DOMAIN}_files.tar ."
2021-01-04 11:22:49 +01:00
docker-compose exec --user www-data nextcloud php occ maintenance:mode --off
2020-09-03 11:42:35 +02:00
}
nextcloud_restore() {
script_env
2021-01-04 11:22:49 +01:00
postgres_restore
2021-01-04 11:30:02 +01:00
docker run -it --rm -v $HOME/backups/${NEXTCLOUD_DOMAIN}:/backup -v nextcloud:/var/www/html alpine:3.12.3 ash -c "cd /var/www/html && tar xvf /backup/${BACKUP_DATE}_${NEXTCLOUD_DOMAIN}_files.tar --strip 1"
2020-09-03 11:42:35 +02:00
}
if [ $# -ge 1 ]; then
if [ "${1}" == "backup" ]; then
script_start
nextcloud_backup
script_end
elif [ "${1}" == "restore" ]; then
script_start
nextcloud_restore
script_end
elif [ "${1}" != "--only-source" ]; then
nextcloud_help
fi
else
nextcloud_help
fi