How to restore a Nextcloud backup
CloudWith a Nextcloud backup in place, it’s time to learn how to restore those backups to a new instance of the on-premises cloud server.
In a recent post, I demonstrated how to back up your Nextcloud installation. That process wound up with a backup of specific folders as well as the required database.
If you’ve taken care of backing up that Nextcloud instance on a regular basis, you should have a most recent backup, on the off-chance something were to befall your server. Should that be the case, you will need to know how to restore said backup.
I’m going to walk you through the process of restoring your backup for Nextcloud.
SEE: Hiring kit: Database administrator (TechRepublic Premium)
What you’ll need
In order to make this work, you’ll need the following:
-
Your backup file for Nextcloud
-
Your backup database for Nextcloud
-
A new installation of Nextcloud that is at the same release level as the backed up instance
-
A user with sudo privileges
As you can see from the list above, what we’re going to do is restore the backup files to a brand new instance of Nextcloud. Because of that, your new instance of Nextcloud must be up and running.
I am going to assume your backup files are named:
How to migrate the backup files to Nextcloud
The first thing you must do is migrate the backup files to the new instance of Nextcloud. This can be done in any way you like. One possibility is by using the Secure Copy command like so:
scp nextcloudbackup.tgz USER@SERVER_IP:/home/user/
Where USER is the username on the remote server and SERVER_IP is the IP address of the new Nextcloud instance.
You will need to do that with both the file and database backup. Once those files are housed in the new location, you’re ready to continue.
How to restore files
The first step is to restore the files backup to the new directory. I will assume your backup file is in .tgz format. Before you move the file, unpack it with the command:
sudo tar xvzf nextcloudbackup.tgz
Now we can use rsync to move it like so:
sudo rsync -Aax nextcloudbackup /var/www/html/nextcloud/
Now that the backup files are in place, it’s time to restore the database.
How to restore the database
I’m going to assume the name of your database is nextcloud. Before you can restore the backup, you have to drop the original, which is done with the command:
sudo mysql -h localhost -u USER -p -e "DROP DATABASE nextcloud"
Where USER Is the username with admin rights.
Now that the original database has been dropped, you need to create a new database with the command:
sudo mysql -h localhost -u root -p -e "CREATE DATABASE nextcloud"
Next, restore the backup to the newly created database with the command:
sudo mysql -h localhost -u USER -p nextcloud < nextclouddb.bak
Where USER is the username with admin rights.
That’s all there is to it. You should now be able to log in to the restored instance of Nextcloud and everything is in working order.
Enjoy the security of having a backup/restore process for your Nextcloud cloud servers.
Data Center Trends Newsletter
DevOps, virtualization, the hybrid cloud, storage, and operational efficiency are just some of the data center topics we’ll highlight. Delivered Mondays and Wednesdays