Skip to content

Commit

Permalink
aio-interface: allow to exclude previews from restore upon instance r…
Browse files Browse the repository at this point in the history
…estore

Signed-off-by: Simon L. <[email protected]>
  • Loading branch information
szaimen committed Nov 8, 2024
1 parent 6625813 commit 73b944f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Containers/borgbackup/backupscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ if [ "$BORG_MODE" = restore ]; then
fi
echo "Restoring '$SELECTED_ARCHIVE'..."

# Exclude previews from restore if selected to speed up process
ADDITIONAL_RSYNC_EXCLUDES=()
if [ -n "$RESTORE_EXCLUDE_PREVIEWS" ]; then
ADDITIONAL_RSYNC_EXCLUDES=(--exclude "nextcloud_aio_nextcloud/appdata_*/preview/**")
echo "Excluding previews from restore"
fi

# Save Additional Backup dirs
if [ -f "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/additional_backup_directories" ]; then
ADDITIONAL_BACKUP_DIRECTORIES="$(cat /nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/additional_backup_directories)"
Expand Down Expand Up @@ -363,6 +370,7 @@ if [ "$BORG_MODE" = restore ]; then
--exclude "nextcloud_aio_mastercontainer/data/daily_backup_running" \
--exclude "nextcloud_aio_mastercontainer/data/session_date_file" \
--exclude "nextcloud_aio_mastercontainer/session/**" \
"${ADDITIONAL_RSYNC_EXCLUDES[@]}" \
/tmp/borg/nextcloud_aio_volumes/ /nextcloud_aio_volumes/; then
RESTORE_FAILED=1
echo "Something failed while restoring from backup."
Expand Down Expand Up @@ -486,6 +494,12 @@ if [ "$BORG_MODE" = restore ]; then
touch "/nextcloud_aio_volumes/nextcloud_aio_nextcloud_data/fingerprint.update"
chmod 777 "/nextcloud_aio_volumes/nextcloud_aio_nextcloud_data/fingerprint.update"

# Add file to Netcloud container to trigger a preview scan the next time it starts
if [ -n "$RESTORE_EXCLUDE_PREVIEWS" ]; then
touch "/nextcloud_aio_volumes/nextcloud_aio_nextcloud_data/trigger-preview.scan"
chmod 777 "/nextcloud_aio_volumes/nextcloud_aio_nextcloud_data/trigger-preview.scan"
fi

# Delete redis cache
rm -f "/mnt/redis/dump.rdb"
fi
Expand Down
6 changes: 6 additions & 0 deletions Containers/nextcloud/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ if [ -f "$NEXTCLOUD_DATA_DIR/fingerprint.update" ]; then
rm "$NEXTCLOUD_DATA_DIR/fingerprint.update"
fi

# Perform preview scan if previews were excluded from restore
if [ -f "$NEXTCLOUD_DATA_DIR/trigger-preview.scan" ]; then
php /var/www/html/occ files:scan-app-data preview -vvv
rm "$NEXTCLOUD_DATA_DIR/trigger-preview.scan"
fi

# AIO one-click settings start # Do not remove or change this line!
# Apply one-click-instance settings
echo "Applying one-click-instance settings..."
Expand Down
1 change: 1 addition & 0 deletions php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@
"BORG_PASSWORD=%BORGBACKUP_PASSWORD%",
"BORG_MODE=%BORGBACKUP_MODE%",
"SELECTED_RESTORE_TIME=%SELECTED_RESTORE_TIME%",
"RESTORE_EXCLUDE_PREVIEWS=%RESTORE_EXCLUDE_PREVIEWS%",
"BACKUP_RESTORE_PASSWORD=%BACKUP_RESTORE_PASSWORD%",
"ADDITIONAL_DIRECTORIES_BACKUP=%ADDITIONAL_DIRECTORIES_BACKUP%",
"BORGBACKUP_HOST_LOCATION=%BORGBACKUP_HOST_LOCATION%",
Expand Down
1 change: 1 addition & 0 deletions php/src/Controller/DockerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function StartBackupContainerRestore(Request $request, Response $response
$config = $this->configurationManager->GetConfig();
$config['backup-mode'] = 'restore';
$config['selected-restore-time'] = $request->getParsedBody()['selected_restore_time'] ?? '';
$config['restore-exclude-previews'] = $request->getParsedBody()['restore-exclude-previews'] ?? '';
$this->configurationManager->WriteConfig($config);

$id = self::TOP_CONTAINER;
Expand Down
9 changes: 9 additions & 0 deletions php/src/Data/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ public function GetSelectedRestoreTime() : string {
return $config['selected-restore-time'];
}

public function GetRestoreExcludePreviews() : string {
$config = $this->GetConfig();
if(!isset($config['restore-exclude-previews'])) {
$config['restore-exclude-previews'] = '';
}

return $config['restore-exclude-previews'];
}

public function GetAIOURL() : string {
$config = $this->GetConfig();
if(!isset($config['AIO_URL'])) {
Expand Down
2 changes: 2 additions & 0 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ public function CreateContainer(Container $container) : void {
$replacements[1] = $this->configurationManager->GetAIOURL();
} elseif ($out[1] === 'SELECTED_RESTORE_TIME') {
$replacements[1] = $this->configurationManager->GetSelectedRestoreTime();
} elseif ($out[1] === 'RESTORE_EXCLUDE_PREVIEWS') {
$replacements[1] = $this->configurationManager->GetRestoreExcludePreviews();
} elseif ($out[1] === 'APACHE_PORT') {
$replacements[1] = $this->configurationManager->GetApachePort();
} elseif ($out[1] === 'TALK_PORT') {
Expand Down
1 change: 1 addition & 0 deletions php/templates/containers.twig
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<option value="{{ restore_time }}">{{ restore_time }} UTC</option>
{% endfor %}
</select>
<input type="checkbox" id="restore-exclude-previews" name="restore-exclude-previews"><label for="restore-exclude-previews">Exclude previews from restore which will speed up the restore process but will trigger a scan of the preview folder as soon as the Nextcloud container starts the next time</label>
<input type="submit" value="Restore selected backup"/>
</form>
{% endif %}
Expand Down

0 comments on commit 73b944f

Please sign in to comment.