How To Complete Nextcloud Backup With a Simple Script

I really like self-hosted solutions in my daily drive. Nextcloud is one of them and most appriciated one. So, if you have this kind of a setup then you need a nextcloud backup. The nextcloud has solid documenting for almost every configuration. I looked there and create a simple script for backup process. It has few simple steps to do:

  • creating a folder that will include all the nextcloud data
  • create a mysql dump for nextcloud database
  • and zip them all
  • remove folder that created in first step

mkdir nextcloud-backup
rsync -Aax /var/www/nextcloud/ ~/nextcloud-backup/nextcloud-dirbkp_`date +"%Y%m%d"`/
mysqldump --lock-tables -hlocalhost -unextcloud -p nextcloud > ~/nextcloud-backup/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
sudo zip -r nc_latest_backup.zip nextcloud-backup/
sudo rm -rf nextcloud-backup/

Be careful before the run script because it will create a zipped file that will be as big as your all nextcloud. Be sure that you have enough disk space.

Save this script as backup_nc.sh and run with sudo sh backup_nc.sh  It will ask for sudo password (if not asked before) and then mysql root user password. The process may take a while according to your data size.

Finally, If you wish pull your backup via SFTP or similar ways.

You may want to checkout my previous post which about complete nextcloud setup. 

Leave a Comment

Your email address will not be published. Required fields are marked *