Back up Nextcloud

Learn how to back up your Nextcloud installation to prevent data loss.

Back up Nextcloud
Learn how to back up your Nextcloud installation to prevent data loss.

You have probably heard that Nextcloud has fallen victim to a targeted ransomware called NextCry. This one
ransomware
encrypts user files and offers this message:

“You have been hacked, your files are encrypted using a strong AES-256 ALGORITHM – Send 0.025 BTC to the next wallet (cryptographic wallet address) AND AFTER PAYMENT CONTACT (the email of the cyber criminals) TO MAKE THE KEY NECESSARY DELETE TO DELETE YOUR FILES ”

The ransomware removes all folders and files that can be used to restore infected files in a clean state and then encrypts the user’s files.

SEE: Hybrid cloud: a guide for IT professionals (download TechRepublic)

That is why you may want to know how to back up your Nextcloud copy. From now on Nextcloud has no official backup solution. According to co-founder of Nextcloud (and just generally great guy), Jos Poortvliet, “we wanted to develop a (backup solution) for (Nextcloud) 18, but the man who worked on it got many things on his plate, so it That will certainly be January. But at some point we really want to do it. ”

So a backup solution could come to Nextcloud in the near future. Until then you need to know how to back up that copy.

What you need

What you need for this to work are:

  • An active copy of Nextcloud

  • A user with sudo rights

  • A location for the backup data

I assume that your copy of Nextcloud is installed in / var / www / html / nextcloud. If yours varies, make that adjustment if necessary.

How to put Nextcloud in maintenance mode

The first thing to do is put your copy of Nextcloud in maintenance mode. To do this, log in to the hosting server and give the commands:

cd / var / www / html / nextcloud
sudo -u www-data php occ maintenance: mode –on

Nextcloud is currently in maintenance mode.

Back up folders

Then there are a number of folders and files that need to be backed up. Instead of backing them up separately, we back up the entire Nextcloud folder with rsync. Here you need a secondary location for the data. I would do this with a few steps:

Make the backup with the following commands:

cd / var / www / html /
sudo rsync -Aavx nextcloud // LOCATION / nextcloud-backup_`date + “% Y% m% d” ‘/

Where LOCATION is the folder where the Nextcloud installation is located. Depending on how much data you have in that folder, this may take some time.

Tar the backup folder with the following command:

tar cfz /LOCATION/nextcloud-backup_DATE.tgz / LOCATION / nextcloud-backup_DATE /

Where LOCATION is the location where the backup is located and DATE is the date associated with the file name.

Back up the database

The folders are not the only one that requires a backup. We also need to back up our database. I assume that you use MySQL or MariaDB. To make a backup of the database, give the command:

sudo mysqldump – one-transaction -h SERVER -u USER -p nextcloud> nextclouddb-backup_`date + “% Y% m% d” `.bak

Where SERVER is the location of the database – if it is hosted on the same machine as Nextcloud, this becomes local host – and USER is a user with MySQL administrator rights.

After you have taken care of both your database and your directory backups, keep them in a safe location.

You probably need to make regular backups of both your Nextcloud directory and your database. So consider creating a cron task for this task (combining both commands in one script).

How to remove your Nextcloud server from maintenance mode

Now that your backups are taken care of, place your Nextcloud server out of maintenance mode with the commands:

cd / var / www / html / nextcloud
sudo -u www-data php occ maintenance: mode –off

Congratulations, a backup has been made of your Nextcloud server. The next time we deal with this topic, we restore the backup to a newly installed copy of Nextcloud.

Cloud Insights newsletter

Your knowledge base for the latest news on AWS, Microsoft Azure, Google Cloud Platform, Docker, SaaS, IaaS, cloud security, containers, the public cloud, the hybrid cloud, the industry cloud and much more.
Delivered on Mondays

Register today

Also see

Image: Jack Wallen

Similar Posts

Leave a Reply