Backing up NextCloud data with Rclone and Backblaze B2

Table of Contents

I’m only backing this up to backblaze b2 right now, I also have a weekly snapshot of my vm. To make our backup i’m using rclone. I have backblaze set to keep a week of changes. The cost is very small, it is costing me about $0.40 a month right now. We are not going to backup all the server, just the data. I also include a week of database dumps. We can reinstall and rebuild with this information.

First we need a couple of items installed.

  • Install some prerequisites: yum install golang git -You should have setup backblaze b2, and created an application key. If not, I will write this up later.
  • Make a place for Go: mkdir $HOME/gopath
  • Add Go’s folder to your path: export GOPATH="$HOME/gopath/"
  • Install rclone in the GO folder: go get
  • Copy the program into your binary folder: cp $GOPATH/bin/rclone /usr/bin/

Now we need to configure rclone to use Backblaze: rclone config

  • Choose New Remote
  • Type Backblaze for remote name
  • Choose 5 for Backblaze B2
  • Enter your Application ID
  • Enter your Application Key
  • Hit N for no
  • Choose Y for yes its ok
  • Choose Quit config

Crontab and schedule

Now that you have it installed we need to setup our script. I made this in /sbin/


sudo -u apache php /path/to/nextcloud/occ maintenance:mode --on
mysqldump --single-transaction -h localhost -unextcloud -p'nextcloud_password' nextcloud > /path/to/nextcloud/data/ncbackup_`date +"%u"`.sql
sudo -u apache php /path/to/nextcloud/occ maintenance:mode --off

/usr/bin/rclone sync \
        --copy-links \
        --b2-hard-delete \
        --fast-list \
        --min-age ${min_age} \
        --transfers ${transfers} \
        --log-level ${log_level} \
        --log-file ${log_file} \
         ${src} ${dest} $@

if [[ $rc != 0 ]]; then
        echo "An error occurred. Please check the logs." | /usr/bin/mail -s "rclone backup error" ${email}
        echo "Backup succeeded" | /usr/bin/mail -s "rclone backup success" ${email}

Now to make a cronjob for the script to run.

crontab -e

0 5 * * * /sbin/ >/dev/null 2>&1

Jason L. Esman avatar
Jason L. Esman
An experienced senior managed service engineer with 20+ years of knowledge in operations and technology management. I am passionate about working to create efficient, scalable, and repeatable technology and support delivery models. I’ve been heavily involved in ITSM/ITIL providing leadership for the development and implementation of Change Management, Problem Management, and Incident Management.
comments powered by Disqus