Categories
Ξ TREND

How to Backup a NextCloud Snap Installation on Linux

Nextcloud is truly the software of the future. With it, it’s easier than ever to set up your own easy-to-use storage solution, similar to Dropbox on Linux. Setting up the software is extremely easy thanks to things like Snap packages. However, it is not that easy to back up a NextCloud Snap installation.

Note: Before backing up to Nextcloud, make sure that all of your files have finished syncing. During the backup process, the NextCloud plugin will shut down, suspending all services for all users connected to it.

stop the server

Creating a Nextcloud backup, especially the Snap version, requires suspending the server software. Without shutting down the Nextcloud server, some files may not be saved, permission errors may occur, and even data may be lost.

Fortunately, suspending a running Nextcloud server is as easy as installing it. To stop the server, open a terminal and get to a root shell using su or sudo -s. Then use the snap stop command to stop all Nextcloud services.

its –

either

sudo -s snap stop nextcloud

Running the quick stop command will disable the SQL database and other running Nextcloud services. It won’t uninstall them, so don’t worry! Your files are safe!

backup folders

With the server temporarily down, it is safe to create a Nextcloud backup. However, before the server-side backup can begin, we recommend creating a backup of the ~/Nextcloud folder for each user. This way, if something happens to the server backup, users will still have a duplicate of their data.

To create a backup of a Nextcloud sync folder, go to any Linux PC using the sync server and open a terminal. In the terminal, use the tar command to create an archive of the ~/Nextcloud folder. Be sure to replace “username” in the following command with your username.

tar -zcvpf nextcloud-local-backup-username.tar.gz ~/Nexcloud

Depending on the size of ~/Nextcloud, the compression process may take a while. When the archiving process is complete, use the GPG command to encrypt the file (for security purposes).

gpg -c nextcloud-local-backup-username.tar.gz rm nextcloud-local-backup-username.tar.gz

GnuPG will generate nextcloud-local-backup-username.tar.gz.gpg.

After GPG finishes the encryption process, place the encrypted backup in a safe place.

Nextcloud Backup

Backing up the Snap version of Nextcloud is by far the easiest, compared to the traditional Nextcloud setup. Since it’s all in the Nextcloud Snap folder, there’s no need to export any SQL databases or mess with individual files. Instead, users can create a full Nextcloud backup by backing up two individual folders.

The first folder to back up within the Nextcloud Snap directory is the configuration directory. To determine the name of the Nextcloud configuration folder, run lsblk and see where it is on the system. As of writing this article, the mount folder is:

/var/lib/snapd/snap/nextcloud/7658

Create a new backup folder inside /home/username/ with the mkdir command and use the cp command to copy everything into it.

mkdir ~/nextcloud-server-backup mkdir ~/nextcloud-server-backup/config sudo cp -rp /var/lib/snapd/snap/nextcloud/7658/* /home/username/nextcloud-server-backup/config

With the Nextcloud configuration files in the backup folder, it’s time to save the data.

mkdir ~/nextcloud-server-backup/data sudo cp -rp /var/snap/nextcloud/common/* /home/username/nextcloud-server-backup/data

Compress the backup

Now that the backup is complete, it is safe to compress the backup into a Tar file for safekeeping. In the terminal, compress the data into a TarGZ file, using the tar command.

Note: Before you compress this backup, make sure you have enough disk space to support it.

tar -zcvpf nextcloud-snap-server-backup.tar.gz ~/nextcloud-server-backup

Depending on how much data is on Nextcloud, this could take a while. When the compression is complete, feel free to move the backup to an external hard drive or backup file server.

encrypt backup

The Nextcloud server has a backup, but it is not secure because it is not encrypted. To make sure the data on your Nextcloud server is safe from eavesdropping, encrypt it with GnuPG.

To encrypt the backup, open a terminal and run the following command:

gpg -c nextcloud-snap-server-backup.tar.gz

Like Nextcloud’s local backup, GPG will generate a nextcloud-snap-server-backup.tar.gz.gpg file. This file is encrypted and safe, so it’s okay to delete the unencrypted file:

rm nextcloud-snap-server-backup.tar.gz

restore backup

Do you need to restore the backup? Start by moving nextcloud-snap-server-backup.tar.gz.gpg to /home/username/.

Then decrypt the file with gpg:

gpg nextcloud-snap-server-backup.tar.gz.gpg

Extract the file with tar.

tar -xvpf nextcloud-snap-server-backup.tar.gz

Please reinstall before attempting to restore the backup (if you are on a new system).

sudo snap install nextcloud sudo snap stop nextcloud

Restore the backup with;

sudo cp -rpf /home/username/nextcloud-server-backup/data/* /var/lib/snapd/snap/nextcloud/7658/ sudo cp -rpf /home/username/nextcloud-server-backup/config/* / var/snap/nextcloud/common/

Finally, start the Nextcloud server with the quickstart command.

sudo snap start nextcloud

By Ivan Rivera

multifaceted individual driven by a thirst for knowledge and creative expression. Armed with an A.A. in Computer Science & Movie Production from Pasadena City College, Ivan is an aspiring author, pouring his imagination onto the pages of captivating stories. With a background as a retired scientist and chartered engineer, his passion for exploration and innovation knows no bounds. In a previous chapter of his life, Ivan served as a marine engineer on superyachts, navigating the seas and embracing the adventure that comes with it. Today, he continues to embark on a new journey, weaving tales that captivate the hearts and minds of readers worldwide.