nc-restore: Fix potential dataloss when restoring backup (fixes #1417)

- nc-restore: Keep old data directory if present
- nc-restore: Temporarily move and restore user files during nc-restore

Signed-off-by: Tobias K <6317548+theCalcaholic@users.noreply.github.com>
Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com>
This commit is contained in:
Tobias K 2023-01-05 02:01:26 +01:00 committed by Tobias Knöppler
parent 5178e5553f
commit 97085dbc3f
No known key found for this signature in database
GPG Key ID: 3510056072886A8F
2 changed files with 23 additions and 0 deletions

View File

@ -114,6 +114,7 @@ tar $compress_arg -cf "$destfile" \
--exclude "nextcloud/data/*/files_versions/*" \
--exclude "nextcloud/data/ncp-update-backups" \
--exclude "nextcloud/data/__groupfolders" \
--exclude "nextcloud/.data_*" \
-C $basedir nextcloud/ \
|| {
echo "error generating backup"

View File

@ -63,9 +63,31 @@ tar $compress_arg -xf "$BACKUPFILE" -C "$TMPDIR" || exit 1
## RESTORE FILES
echo "restore files..."
[[ -d "$NCDIR/data" ]] && {
DATA_BKP_DIR="$(mktemp -d -p "$NCDIR/.." nc-data-XXXXXX)"
mv -T "$NCDIR/data" "$DATA_BKP_DIR/"
}
rm -rf "$NCDIR"
mv -T "$TMPDIR"/nextcloud "$NCDIR" || { echo "Error restoring base files"; exit 1; }
if [[ -n "$DATA_BKP_DIR" ]]
then
echo "Restoring $NCDIR/data..."
target="$NCDIR/data"
[[ -d "$target" ]] && target="$NCDIR/.data_$(date)"
mv -T "$DATA_BKP_DIR" "$target"
else
fi
if [[ -n "$DATA_BKP_DIR" ]]
then
echo "Restoring $NCDIR/data..."
target="$NCDIR/data"
[[ -d "$target" ]] && target="$NCDIR/.data_$(date)"
mv -T "$DATA_BKP_DIR" "$target"
else
fi
# update NC database password to this instance
sed -i "s|'dbpassword' =>.*|'dbpassword' => '$DBPASSWD',|" /var/www/nextcloud/config/config.php