Skip to content

Instantly share code, notes, and snippets.

@branneman
Last active February 28, 2021 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save branneman/90df61140051fe8ad510ec6cdb6612ce to your computer and use it in GitHub Desktop.
Save branneman/90df61140051fe8ad510ec6cdb6612ce to your computer and use it in GitHub Desktop.

Automate backups: Nextcloud to S3

Assumptions

  • Disk space: at least 3× the size of the /var/www/nextcloud directory is available on /var/backups
  • Nextcloud is installed into /var/www/nextcloud as user www-data
  • AWS cli is installed and configured with credentials
  • mysqldump is installed
  • rsync is installed

Setup

Create file /root/cron-env with these contents:

HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
LANG=en_US.UTF-8
SHELL=/bin/sh
PWD=/root

Create executable file /root/run-as-cron with these contents:

#!/bin/bash
/usr/bin/env -i $(cat /root/cron-env) "$@"

Create executable file /root/backup-nextcloud-to-s3.bash with these contents.

Configure cron

0 5 * * * /root/backup-nextcloud-to-s3.bash

Run manually

./run-as-cron /root/backup-nextcloud-to-s3.bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment