An ansible role that creates a backup of a Nextcloud server. The backup is kept on the server (unless you fetch it).
The roles requires the following tools to be available on the host:
- tar
- gzip
- rsync
- a mysql or postgreSQL client if the database has to be dumped.
You'll need enough space on the target file system, depending on the size of your nextcloud server.
The role has to know where the server files are, how to access it and where to store the backup.
nextcloud_backup_target_dir: "/opt/nextcloud_backups"
nextcloud_webroot: "/opt/nextcloud"
# nextcloud_data_dir: "/var/ncdata" # optional.
nextcloud_websrv_user: "www-data" # you may need to change this to the nextcloud file owner depending of your setup and OS
The backup owner can be adjusted with. This may be useful when operating user is different than nextcloud's process owner.
nextcloud_backup_owner: "www-data" # user name who will get owner on backup_target_dir and final archive
nextcloud_backup_group: "www-data" # user group who will get owner on backup_target_dir and final archive
The backup name can be adjusted with
nextcloud_instance_name: "nextcloud" # a human identifier for the server
nextcloud_backup_suffix: "" # some arbitrary information at the end of the archive name
nextcloud_backup_format: "tgz" # extension of the archive. use a supported format used by the archive module (Choices: bz2, gz, tar, xz, zip)
Or you can change it completely by redefining
nc_archive_name: "{{ nextcloud_instance_name }}_nextcloud-{{ nc_status.versionstring }}_{{ ansible_date_time.iso8601_basic_short }}{{ nextcloud_backup_suffix }}"
The role will always:
- backup the server's config
- create a list of installed & enabled applications(along with the version numbers)
You can adjust the scope of the backup by enabling/disabling some flags defined in default:
nextcloud_backup_download_server_archive: true
nextcloud_backup_app_data: true
nextcloud_backup_user: true
nextcloud_backup_database: true
Role can download the proper server archive from the nextcloud download site and add it to backup archive.
It can be turned on using: nextcloud_backup_download_server_archive
variable.
You may want to exclude some app_data folders from the backup. But you cannot target a specific app to backup, this requires knowledge of the app's code.
nextcloud_backup_app_data_exclude_folder:
- preview
By default the preview folder is excluded from the backup as it can be notoriously large
You can exclude a list of user(s) from the backup
nextcloud_backup_exclude_users: []
You can also decide to include or not some side-folders.
nextcloud_backup_user_files_trashbin: true
nextcloud_backup_user_files_versions: true
nextcloud_backup_user_uploads: true
nextcloud_backup_user_cache: true
You can fetch created backup from remote by setting these variables.
WARNING: user which you are used in Ansible has to be set as backup owner due to Ansible limitation on using become
with ansible.builtin.fetch
nextcloud_backup_fetch_to_local: true
nextcloud_backup_fetch_local_path: "/local_path/nextcloud_backup"
You can leave the server in maintenance mode at the end of the process by turning false
nextcloud_exit_maintenance_mode: true
None
- hosts: nextcloud
roles:
- role: aalaesar.backup_nextcloud
- hosts: nextcloud
roles:
- role: aalaesar.backup_nextcloud
vars:
nextcloud_backup_suffix: _only_app_data
nextcloud_backup_user: false
nextcloud_backup_database: false
GPL-3.0