Skip to content

Commit

Permalink
nc-restore: Fix potential dataloss when restoring backup (fixes #1417)
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
theCalcaholic committed Jan 5, 2023
1 parent 6b1d28a commit 73b5000
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/ncp/BACKUPS/nc-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions bin/ncp/BACKUPS/nc-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73b5000

Please sign in to comment.