aalaesar.backup_nextcloud

Ansible-lint status YAML-lint status

backup_nextcloud

This is an Ansible role that creates a backup of a Nextcloud server. The backup will be stored on the server (unless you fetch it).

Requirements

To use this role, the following tools need to be installed on your server:

  • tar
  • gzip
  • rsync
  • a MySQL or PostgreSQL client if you need to back up the database.

Make sure you have enough space on your server for the backup, depending on how much data you have in Nextcloud.

Role Variables

Finding the Nextcloud server

The role needs to know where the Nextcloud files are located, how to access them, and where to save 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 based on your system and setup.

Setting the backup owner

You can change who owns the backup files. This is helpful if the user running the backup is different from Nextcloud's owner.

nextcloud_backup_owner: "www-data" # User who will own the backup directory and final archive.
nextcloud_backup_group: "www-data" # User group that will own the backup directory and final archive.

Setting the backup name

You can customize the backup name with:

nextcloud_instance_name: "nextcloud" # A name for your server.
nextcloud_backup_suffix: "" # Additional info for the backup name.
nextcloud_backup_format: "tgz" # Format of the backup file. Use supported formats (bz2, gz, tar, xz, zip).

You can completely redefine the name with:

nc_archive_name: "{{ nextcloud_instance_name }}_nextcloud-{{ nc_status.versionstring }}_{{ ansible_date_time.iso8601_basic_short }}{{ nextcloud_backup_suffix }}"

Customizing the backup contents

The role will always:

  • back up the server's configuration
  • create a list of installed and enabled applications with their version numbers

You can adjust what to back up by turning these options on or off:

nextcloud_backup_download_server_archive: true
nextcloud_backup_app_data: true
nextcloud_backup_user: true
nextcloud_backup_database: true

Including the Nextcloud server archive in the backup

You can download the appropriate server archive from the Nextcloud website and include it in the backup. Turn this on with nextcloud_backup_download_server_archive.

Customizing app data backup

You can exclude some app data folders from the backup. However, you can't specify a particular app; you need to know the app's code.

nextcloud_backup_app_data_exclude_folder:
  - preview

By default, the preview folder is excluded because it can take up a lot of space.

Customizing user backups

You can exclude specific users from being backed up:

nextcloud_backup_exclude_users: []

You can also choose whether to include certain user folders:

nextcloud_backup_user_files_trashbin: true
nextcloud_backup_user_files_versions: true
nextcloud_backup_user_uploads: true
nextcloud_backup_user_cache: true

Fetching backup from remote to local machine

You can copy the created backup from the server to your local machine by using these variables. Note: The user running Ansible must be set as the backup owner due to a limitation with become.

nextcloud_backup_fetch_to_local: true
nextcloud_backup_fetch_local_path: "/local_path/nextcloud_backup"

Other settings

You can keep the server in maintenance mode after the backup by setting this to false:

nextcloud_exit_maintenance_mode: true

Dependencies

None

Example Playbook

Full backup of your Nextcloud server

- hosts: nextcloud
  roles:
    - role: aalaesar.backup_nextcloud

Partial backup with only the app data

- hosts: nextcloud
  roles:
    - role: aalaesar.backup_nextcloud
  vars:
    nextcloud_backup_suffix: _only_app_data
    nextcloud_backup_user: false
    nextcloud_backup_database: false

License

GPL-3.0

Informazioni sul progetto

Create a backup of your nextcloud server with this ansible role

Installa
ansible-galaxy install aalaesar.backup_nextcloud
Licenza
agpl-3.0
Download
695
Proprietario
Yet another DevOps. I just want things to become easier and faster, ... and understand how it works ! That's a lot of work ...