Jump to content

Backup - Copy - Restore Nextcloud in new Unraid Server


rojarrolla

Recommended Posts

Hi guys!

 

I've been crawling the internet and not been able to find anything clear. 

 

Currently I want to have a backup unraid server in case of hardware failure.

 

So I want to go from server A to server B.

 

I have nextcloud running and I would like to backup the whole nextcloud (docker container, MariaDB and Nextcloud Share).

 

I was thinking to run a backup on server A and recover it on server B. then to copy the whole Nextcloud share.

 

I don't know if it is that simple, but at leasts shows you what I am trying to achieve.

 

Have any of you guys done this?

 

I mean If you have a couple of users relying on nextcloud and if it breaks, what would happen?

 

Thanks a lot.

 

 

Link to comment
11 hours ago, rojarrolla said:

I didn't know that was even possible, but if you write a tutorial of how to do it I will make another showing how to do it the way I did it.

 

Do we have a deal?

 

 


I haven’t done it which was why it was a question rather than a suggestion.   I am relatively certain that it is possible though.

Link to comment
  • 2 years later...

Old thread, but seeing as I've just figured out how to do this for myself I'm posting in case it's useful for anyone else. Basically Nextcloud doesn't give you an easy to use backup solution, however I've read that the NextCloud-AIO instance does. I just have regular NextCloud. According to the documentation here, it says that you should copy the installation and the database, and later use these to restore. My use case is to copy and encrypt that data to cloud storage, in my case DropBox. 

 

The basic steps are:

 

1. Get rclone installed on your Unraid instance

2. Configure rclone for your chosen cloud provider (in my case, DropBox) and set up the remote rclone destination

3. [Optional] Use rclone to encrypt your remote cloud destination

4. Install the "User Scripts" plugin in Unraid in case you don't already have it

5. Use my script below with your appropriate modifications as a "User Script".

6. Run the copy script manually for the first time (it will take a long time depending on your NC install size, network etc.)

7. Once your initial copy is done, enable scheduler (I've set my to daily) using "User Scripts" in unraid.

8. That's it!

 

Note that I haven't tried a restore, and I'm not too fussed about it because I know I can get my data in the worst case scenario. I'm not too bothered about the rest of my NC install.

#!/bin/bash

# Script to backup NextCloud installation to DropBox
# v1.0 22nd June 2024 - Initial

# Check if previous run worked, abort otherwise
echo Checking for existing lock file ...
if [ -f /tmp/nc_backup.lock ] ; then 
    /usr/local/emhttp/webGui/scripts/notify -e "NextCloudBackup" -s "NC Daily Backup" -d "Finished" -i "ERROR" -m "The NexCloud backup script FAILED"
    echo ERROR: Lock file exists, likely that a previous run failed. Aborting!
    exit 1
fi

# Create lock file while the script works

echo Creating new lock file ...
touch /tmp/nc_backup.lock

# Perform the backup while in maintenance mode

echo Putting NextCloud in maintenance mode ...
docker exec nextcloud occ maintenance:mode --on

# dump the database

echo Dumping the database ...
docker exec mariadb mysqldump --single-transaction -u mydatabasename -mypassword nextcloud > /tmp/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak

# copy the database

echo Deleting any existing database files from the remote cloud storage ...
rclone delete NextCloudBackupEncrypted:daily_db

echo Copying the dumped database ...
rclone copy /tmp/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak NextCloudBackupEncrypted:daily_db/

echo Cleaning up dumped database ...
rm /tmp/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak

# sync all other files

echo Syncing NextCloud installation ...
rclone sync --transfers 12 --tpslimit 12 /mnt/user/nextcloud/ NextCloudBackupEncrypted:daily/

echo Turning off maintenance mode ...
docker exec nextcloud occ maintenance:mode --off

# Remove the lock when all done

echo Removing lock file for next run ...
rm /tmp/nc_backup.lock

# Finished

/usr/local/emhttp/webGui/scripts/notify -e "NextCloudBackup" -s "NC Daily Backup" -d "Finished" -i "normal" -m "The NextCloud backup script SUCCEEDED"
exit 0

 

Edited by DANgerous25
cleaned up unnecessary commands
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...