yes.
to make it better you can combine it with restic. restic takes care about the lifecycle of your backups since it is backup program, encrypts the files again, can use rclone as a target repo and is cool.
https://restic.readthedocs.io/en/latest/010_introduction.html
An example script:
#!/bin/bash
export RESTIC_REPOSITORY="/var/nc-backup"
export RESTIC_PASSWORD="EAtcVlENiC6TlMwH73X9PRfD17vsEEHI"
# abort entire script if any command fails
set -e
# Make sure nextcloud is enabled when we are done
trap "sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off" EXIT
# set nextcloud to maintenance mode
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
# backup the database
sudo docker exec -t postgres pg_dump -c -U postgres nextcloud | /usr/local/bin/restic backup --stdin --stdin-filename db_postgres_nextcloud.sql
# or in case of mysql
mysqldump --single-transaction -h localhost -u {{ nc_db_user }} -p{{ nc_db_passwd }} {{ nc_db }} | /usr/local/bin/restic backup --stdin --stdin-filename db_mysql_nextcloud.sql
# backup the data dir
/usr/local/bin/restic backup /var/nc-data
# backup the nextcloud dir
/usr/local/bin/restic backup /var/www/nextcloud
# turn maintenance mode off
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off
# delete trap
trap "" EXIT
# clean up backup dir
/usr/local/bin/restic forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75