{"id":103,"date":"2021-08-06T20:18:02","date_gmt":"2021-08-06T12:18:02","guid":{"rendered":"https:\/\/www.soholab.tw\/?p=103"},"modified":"2021-08-06T20:18:02","modified_gmt":"2021-08-06T12:18:02","slug":"how-to-backup-a-nextcloud-snap-installation-on-linux","status":"publish","type":"post","link":"https:\/\/soholab.tw\/?p=103","title":{"rendered":"How To Backup A NextCloud Snap Installation On Linux"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.addictivetips.com\/ubuntu-linux-tips\/backup-nextcloud-snap-installation-on-linux\/\">https:\/\/www.addictivetips.com\/ubuntu-linux-tips\/backup-nextcloud-snap-installation-on-linux\/<\/a><\/p>\n\n\n\n<p>Nextcloud truly is the software of the future. Thanks to it, it\u2019s simpler than ever to spin up your own user-friendly, Dropbox-like\u00a0<a href=\"https:\/\/www.addictivetips.com\/ubuntu-linux-tips\/set-up-your-own-cloud-storage-on-linux-next-cloud\/\">storage solution on Linux<\/a>. Setup for the software is extremely easy thanks to things like Snap packages.\u00a0However it isn\u2019t as easy to backup a NextCloud Snap installation.<\/p>\n\n\n\n<p>Note: Before doing a Nextcloud backup, ensure the entirety of your files has finished syncing. During the backup process, the NextCloud snap will shut off, suspending all services to all users connected to it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Stop The Server<\/h2>\n\n\n\n<p>Creating a backup of Nextcloud, especially the Snap version, requires the suspension of the server software. Without turning the Nextcloud server off, certain files may fail to save, permission errors could arise, and even data could be lost.<\/p>\n\n\n\n<p>Luckily, suspending a running Nextcloud server is just about as easy as installing it! To stop the server, open up a terminal and gain a root shell using&nbsp;<strong>su&nbsp;<\/strong>or&nbsp;<strong>sudo -s<\/strong>. Then, use the&nbsp;<strong>snap stop<\/strong>&nbsp;command to stop all Nextcloud services.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">su -<\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo -s\n\nsnap stop nextcloud<\/pre>\n\n\n\n<p>Running the&nbsp;<strong>snap stop&nbsp;<\/strong>command will disable the SQL database, and other running Nextcloud services. It will not uninstall them, so don\u2019t worry! Your files are safe!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Back Up Folders<\/h2>\n\n\n\n<p>With the server temporarily shut off, it\u2019s safe to create a backup of Nextcloud. However, before the server-side backup can begin, we recommend creating a backup of the&nbsp;<strong>~\/Nextcloud&nbsp;<\/strong>folder for each user. This way, if anything happens to the server backup, users will still have a duplicate of their data.<\/p>\n\n\n\n<p>To create a backup of a Nextcloud sync folder, go to any Linux PC that uses the sync server, and open up a terminal. In the terminal, use the&nbsp;<strong>Tar<\/strong>&nbsp;command to create an archive of the&nbsp;<strong>~\/Nextcloud<\/strong>&nbsp;folder. Be sure to replace \u201cusername\u201d in the command below with your username.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tar -zcvpf nextcloud-local-backup-username.tar.gz ~\/Nexcloud<\/pre>\n\n\n\n<p>Depending on how large&nbsp;<strong>~\/Nextcloud<\/strong>&nbsp;is, the compression process may take a while. When the archiving process is complete, use the&nbsp;<strong>GPG<\/strong>&nbsp;command to encrypt the archive (for security purposes.)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gpg -c nextcloud-local-backup-username.tar.gz\n\nrm nextcloud-local-backup-username.tar.gz<\/pre>\n\n\n\n<p>GnuPG will output&nbsp;<strong>nextcloud-local-backup-username.tar.gz.gpg<\/strong>.<\/p>\n\n\n\n<p>After GPG finishes the encryption process, place the encrypted backup somewhere safe.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Back Up Nextcloud<\/h2>\n\n\n\n<p>Backing up the Snap version of Nextcloud is by far the easiest, compared to the traditional Nextcloud setup. Since everything is in the Nextcloud Snap folder, there\u2019s no need to export any SQL databases or mess with individual files. Instead, users can create a complete backup of Nextcloud by making a copy of two individual folders.<\/p>\n\n\n\n<p>The first folder to backup within the Nextcloud Snap directory is the configuration directory. To determine the name of the Nextcloud config folder, run&nbsp;<strong>lsblk<\/strong>&nbsp;and see where it is on the system. As of writing this article, the mount folder is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/var\/lib\/snapd\/snap\/nextcloud\/7658<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cloud.addictivetips.com\/wp-content\/uploads\/2018\/07\/nextcloud-location.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.addictivetips.com\/ubuntu-linux-tips\/backup-nextcloud-snap-installation-on-linux\/attachment\/nextcloud-location\/\"><\/a><\/p>\n\n\n\n<p>Make a new backup folder inside of&nbsp;<strong>\/home\/username<\/strong>\/ with the&nbsp;<strong>mkdir&nbsp;<\/strong>command and use the&nbsp;<strong>cp&nbsp;<\/strong>command to copy everything to it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir ~\/nextcloud-server-backup\n\nmkdir ~\/nextcloud-server-backup\/config\nsudo cp -rp \/var\/lib\/snapd\/snap\/nextcloud\/7658\/* \/home\/username\/nextcloud-server-backup\/config<\/pre>\n\n\n\n<p>With the configuration files for Nextcloud in the backup folder, it\u2019s time to save the data.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir ~\/nextcloud-server-backup\/data\n\nsudo cp -rp \/var\/snap\/nextcloud\/common\/* \/home\/username\/nextcloud-server-backup\/data<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Compress The Backup<\/h2>\n\n\n\n<p>Now that the backup is complete, it\u2019s safe to compress the backup into a Tar archive for safekeeping. In the terminal, compress the data into a TarGZ archive, using the&nbsp;<strong>tar&nbsp;<\/strong>command.<\/p>\n\n\n\n<p>Note: before compressing this backup, ensure you have enough disk space to support it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tar -zcvpf nextcloud-snap-server-backup.tar.gz ~\/nextcloud-server-backup<\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Encrypt Backup<\/h2>\n\n\n\n<p>The Nextcloud server has a backup but it\u2019s not safe as it isn\u2019t encrypted. To ensure the data on your Nextcloud server is safe from eavesdropping, encrypt it with GnuPG.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cloud.addictivetips.com\/wp-content\/uploads\/2018\/07\/nextcloud-encrypt-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.addictivetips.com\/ubuntu-linux-tips\/backup-nextcloud-snap-installation-on-linux\/attachment\/nextcloud-encrypt\/\"><\/a><\/p>\n\n\n\n<p>To encrypt the backup, open up a terminal and run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gpg -c nextcloud-snap-server-backup.tar.gz<\/pre>\n\n\n\n<p>Like the Nextcloud local backup, GPG will output a&nbsp;<strong>nextcloud-snap-server-backup.tar.gz.gpg<\/strong>&nbsp;file. This file is encrypted and safe, so it\u2019s OK to delete the unencrypted archive:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rm nextcloud-snap-server-backup.tar.gz<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Restore Backup<\/h2>\n\n\n\n<p>Need to restore the backup? Start out by moving nextcloud-snap-server-backup.tar.gz.gpg to&nbsp;<strong>\/home\/username\/<\/strong>.<\/p>\n\n\n\n<p>Next, decrypt the archive with&nbsp;<strong>gpg<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gpg nextcloud-snap-server-backup.tar.gz.gpg<\/pre>\n\n\n\n<p>Extract the archive, using&nbsp;<strong>tar<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tar -xvpf nextcloud-snap-server-backup.tar.gz<\/pre>\n\n\n\n<p>Reinstall before trying to restore the backup (if on a new system).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo snap install nextcloud\n\nsudo snap stop nextcloud<\/pre>\n\n\n\n<p>Restore the backup with;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo cp -rpf \/home\/username\/nextcloud-server-backup\/data\/* \/var\/lib\/snapd\/snap\/nextcloud\/7658\/\n\nsudo cp -rpf \/home\/username\/nextcloud-server-backup\/config\/* \/var\/snap\/nextcloud\/common\/<\/pre>\n\n\n\n<p>Finally, start up the Nextcloud server with the&nbsp;<strong>snap start&nbsp;<\/strong>command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo snap start nextcloud<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.addictivetips.com\/ubuntu-linux-tips\/backup- [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/soholab.tw\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soholab.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soholab.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soholab.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soholab.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":0,"href":"https:\/\/soholab.tw\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"https:\/\/soholab.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soholab.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soholab.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}