mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 06:26:57 +00:00
Merge pull request #908 from nextcloud/enh/722/automatic-updates
allow to run daily backups without automatic updates
This commit is contained in:
commit
70c4223a29
17 changed files with 203 additions and 89 deletions
|
|
@ -88,11 +88,13 @@ COPY start.sh /usr/bin/
|
|||
COPY backup-time-file-watcher.sh /
|
||||
COPY session-deduplicator.sh /
|
||||
COPY cron.sh /
|
||||
COPY daily-backup.sh /
|
||||
COPY supervisord.conf /
|
||||
RUN chmod +x /usr/bin/start.sh; \
|
||||
chmod +x /cron.sh; \
|
||||
chmod +x /session-deduplicator.sh; \
|
||||
chmod +x /backup-time-file-watcher.sh; \
|
||||
chmod +x /daily-backup.sh; \
|
||||
chmod a+r /Caddyfile
|
||||
|
||||
USER root
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ file_present() {
|
|||
if [ "$FILE_PRESENT" = 0 ]; then
|
||||
restart_process
|
||||
else
|
||||
if [ -n "$BACKUP_TIME" ] && [ "$(cat "/mnt/docker-aio-config/data/daily_backup_time")" != "$BACKUP_TIME" ]; then
|
||||
if [ -n "$BACKUP_TIME" ] && [ "$(head -1 "/mnt/docker-aio-config/data/daily_backup_time")" != "$BACKUP_TIME" ]; then
|
||||
restart_process
|
||||
fi
|
||||
fi
|
||||
FILE_PRESENT=1
|
||||
BACKUP_TIME="$(cat "/mnt/docker-aio-config/data/daily_backup_time")"
|
||||
BACKUP_TIME="$(head -1 "/mnt/docker-aio-config/data/daily_backup_time")"
|
||||
else
|
||||
if [ "$FILE_PRESENT" = 1 ]; then
|
||||
restart_process
|
||||
|
|
|
|||
|
|
@ -3,18 +3,25 @@
|
|||
while true; do
|
||||
if [ -f "/mnt/docker-aio-config/data/daily_backup_time" ]; then
|
||||
set -x
|
||||
BACKUP_TIME="$(cat "/mnt/docker-aio-config/data/daily_backup_time")"
|
||||
DAILY_BACKUP=1
|
||||
BACKUP_TIME="$(head -1 "/mnt/docker-aio-config/data/daily_backup_time")"
|
||||
export BACKUP_TIME
|
||||
export DAILY_BACKUP=1
|
||||
if [ "$(sed -n '2p' "/mnt/docker-aio-config/data/daily_backup_time")" != 'automaticUpdatesAreNotEnabled' ]; then
|
||||
export AUTOMATIC_UPDATES=1
|
||||
else
|
||||
export AUTOMATIC_UPDATES=0
|
||||
export START_CONTAINERS=1
|
||||
fi
|
||||
set +x
|
||||
else
|
||||
BACKUP_TIME="04:00"
|
||||
DAILY_BACKUP=0
|
||||
export BACKUP_TIME="04:00"
|
||||
export DAILY_BACKUP=0
|
||||
fi
|
||||
|
||||
if [ -f "/mnt/docker-aio-config/data/daily_backup_running" ]; then
|
||||
LOCK_FILE_PRESENT=1
|
||||
export LOCK_FILE_PRESENT=1
|
||||
else
|
||||
LOCK_FILE_PRESENT=0
|
||||
export LOCK_FILE_PRESENT=0
|
||||
fi
|
||||
|
||||
# Allow to continue directly if e.g. the mastercontainer was updated. Otherwise wait for the next execution
|
||||
|
|
@ -25,61 +32,7 @@ while true; do
|
|||
fi
|
||||
|
||||
if [ "$DAILY_BACKUP" = 1 ]; then
|
||||
echo "Daily backup has started"
|
||||
|
||||
# Delete all active sessions and create a lock file
|
||||
# But don't kick out the user if the mastercontainer was just updated since we block the interface either way with the lock file
|
||||
if [ "$LOCK_FILE_PRESENT" = 0 ]; then
|
||||
rm -f "/mnt/docker-aio-config/session/"*
|
||||
fi
|
||||
sudo -u www-data touch "/mnt/docker-aio-config/data/daily_backup_running"
|
||||
|
||||
# Check if apache is running/stopped, watchtower is stopped and backupcontainer is stopped
|
||||
APACHE_PORT="$(docker inspect nextcloud-aio-apache --format "{{.HostConfig.PortBindings}}" | grep -oP '[0-9]+' | head -1)"
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-apache$" && ! nc -z nextcloud-aio-apache "$APACHE_PORT"; do
|
||||
echo "Waiting for apache to become available"
|
||||
sleep 30
|
||||
done
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-watchtower$"; do
|
||||
echo "Waiting for watchtower to stop"
|
||||
sleep 30
|
||||
done
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-borgbackup$"; do
|
||||
echo "Waiting for borgbackup to stop"
|
||||
sleep 30
|
||||
done
|
||||
|
||||
# Update the mastercontainer
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/UpdateMastercontainer.php
|
||||
|
||||
# Wait for watchtower to stop
|
||||
if ! docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-watchtower$"; then
|
||||
echo "Something seems to be wrong: Watchtower should be started at this step."
|
||||
else
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-watchtower$"; do
|
||||
echo "Waiting for watchtower to stop"
|
||||
sleep 30
|
||||
done
|
||||
fi
|
||||
|
||||
# Execute the backup itself and some related tasks
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/DailyBackup.php
|
||||
|
||||
# Delete the lock file
|
||||
rm -f "/mnt/docker-aio-config/data/daily_backup_running"
|
||||
|
||||
# Wait for the nextcloud container to start and send if the backup was successful
|
||||
if ! docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-nextcloud$"; then
|
||||
echo "Something seems to be wrong: Nextcloud should be started at this step."
|
||||
else
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-nextcloud$" && ! nc -z nextcloud-aio-nextcloud 9000; do
|
||||
echo "Waiting for the Nextcloud container to start"
|
||||
sleep 30
|
||||
done
|
||||
fi
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php
|
||||
|
||||
echo "Daily backup has finished"
|
||||
bash /daily-backup.sh
|
||||
fi
|
||||
|
||||
# Make sure to delete the lock file always
|
||||
|
|
|
|||
77
Containers/mastercontainer/daily-backup.sh
Normal file
77
Containers/mastercontainer/daily-backup.sh
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Daily backup has started"
|
||||
|
||||
# Delete all active sessions and create a lock file
|
||||
# But don't kick out the user if the mastercontainer was just updated since we block the interface either way with the lock file
|
||||
if [ "$LOCK_FILE_PRESENT" = 0 ]; then
|
||||
rm -f "/mnt/docker-aio-config/session/"*
|
||||
fi
|
||||
sudo -u www-data touch "/mnt/docker-aio-config/data/daily_backup_running"
|
||||
|
||||
# Check if apache is running/stopped, watchtower is stopped and backupcontainer is stopped
|
||||
APACHE_PORT="$(docker inspect nextcloud-aio-apache --format "{{.HostConfig.PortBindings}}" | grep -oP '[0-9]+' | head -1)"
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-apache$" && ! nc -z nextcloud-aio-apache "$APACHE_PORT"; do
|
||||
echo "Waiting for apache to become available"
|
||||
sleep 30
|
||||
done
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-watchtower$"; do
|
||||
echo "Waiting for watchtower to stop"
|
||||
sleep 30
|
||||
done
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-borgbackup$"; do
|
||||
echo "Waiting for borgbackup to stop"
|
||||
sleep 30
|
||||
done
|
||||
|
||||
# Update the mastercontainer
|
||||
if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/UpdateMastercontainer.php
|
||||
fi
|
||||
|
||||
# Wait for watchtower to stop
|
||||
if [ "$AUTOMATIC_UPDATES" = 1 ] && ! docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-watchtower$"; then
|
||||
echo "Something seems to be wrong: Watchtower should be started at this step."
|
||||
else
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-watchtower$"; do
|
||||
echo "Waiting for watchtower to stop"
|
||||
sleep 30
|
||||
done
|
||||
fi
|
||||
|
||||
# Stop containers if required
|
||||
if [ "$DAILY_BACKUP" != 1 ] || [ "$STOP_CONTAINERS" = 1 ]; then
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StopContainers.php
|
||||
fi
|
||||
|
||||
# Execute the backup itself and some related tasks (also stops the containers)
|
||||
if [ "$DAILY_BACKUP" = 1 ]; then
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/CreateBackup.php
|
||||
fi
|
||||
|
||||
# Start and/or update containers
|
||||
if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartAndUpdateContainers.php
|
||||
else
|
||||
if [ "$START_CONTAINERS" = 1 ]; then
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartContainers.php
|
||||
fi
|
||||
fi
|
||||
|
||||
# Delete the lock file
|
||||
rm -f "/mnt/docker-aio-config/data/daily_backup_running"
|
||||
|
||||
if [ "$DAILY_BACKUP" = 1 ]; then
|
||||
# Wait for the nextcloud container to start and send if the backup was successful
|
||||
if ! docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-nextcloud$"; then
|
||||
echo "Something seems to be wrong: Nextcloud should be started at this step."
|
||||
else
|
||||
while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-nextcloud$" && ! nc -z nextcloud-aio-nextcloud 9000; do
|
||||
echo "Waiting for the Nextcloud container to start"
|
||||
sleep 30
|
||||
done
|
||||
fi
|
||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php
|
||||
fi
|
||||
|
||||
echo "Daily backup has finished"
|
||||
|
|
@ -246,7 +246,7 @@ if ! [ -f "/mnt/ncdata/skip.update" ]; then
|
|||
fi
|
||||
|
||||
# Performing update of all apps if daily backups are enabled, running and successful and if it is saturday
|
||||
if [ "$DAILY_BACKUP_RUNNING" = 'yes' ] && [ "$(date +%u)" = 6 ]; then
|
||||
if [ "$UPDATE_NEXTCLOUD_APPS" = 'yes' ] && [ "$(date +%u)" = 6 ]; then
|
||||
UPDATED_APPS="$(php /var/www/html/occ app:update --all)"
|
||||
if [ -n "$UPDATED_APPS" ]; then
|
||||
bash /notify.sh "Your apps just got updated!" "$UPDATED_APPS"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue