Skip to content

A shell script to backup nextcloud according to the official documentation

License

Notifications You must be signed in to change notification settings

asmw/nextcloud-backup.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

nextcloud-backup.sh

A shell script to backup nextcloud according to the official documentation.

The script switches on maintenance mode, rsyncs the nextcloud and data folder and dumps the mysql database. On exit maintenance mode is disabled again.

Features

  • Toggles maintenance mode
  • Extracts data folder location and database parameters from the nextcloud config

Requirements

  • php
  • rsync
  • sudo
  • mysqldump

The script assumes that it can run sudo as the owner of the nextcloud occ script (i.e. www-data)

Usage

nextcloud-backup.sh [/path/to/nextcloud] [/path/to/backup] [backup suffix]

Defaults for source and destination are /var/www/nextcloud and /mnt/backups/nextcloud The default suffix for backup folders and the SQL dump is _$(date + %Y%m%d)

Example

nextcloud-backup.sh /var/www/nextcloud /mnt/backups/nextcloud

Caveats

The default rsync settings are suitable for backup onto a CIFS share which cannot preserve owner/group. to override pass something like RSYNC_ARGS="-avx --delete" in the environment.

Environment variables

  • RSYNC_ARGS: arguments passed to rsync (default: -avx --no-owner --no-group --delete)
  • SUFFIX: the backup folder and SQL dump suffix (default: _$(date +"%Y%m%d"))
  • DRYRUN: prefixed to all commands which do work, i.e. rsync/php/sudo, set to echo for a dryrun (default is empty)
  • PREPARE: Run before mysqldump + rsyn is run (default is empty)
  • TEARDOWN: Run after mysqldump and rsync (default is empty)

About

A shell script to backup nextcloud according to the official documentation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages