Yes to both, the above should still work fine, now (after a required edit) via copy&paste the whole code block as well, only the “/mnt/mybackuplocation” needs to be adjusted of course, so that you are in the root of the drive where the dietpi-backup directory is stored.
I assume that this
chmod +x /etc/cron.daily/backup
needs to be outside the script / code tags and has to be done after editing and saving the backup script?
Thx!
Some things are important to me:
-
An exact copy of my Data / Files to a 2nd NAS
Encryption isn’t necessary so I can browse it directly on the 2nd NAS
(For me that is a Synology system at a physical different location in case something happens to the 1st NAS (in any form: Data corruption, Virus, Burglary, Fire, Water damage etc.) -
An exact copy of my (Nextcloud) Database to a 2nd NAS, Will this script also take care of the Nextcloud database ans not only the files?
-An exact copy of the Operating System (OS) to an USB-drive and Harddisk.
(In case the USB-drive dies before the Harddisk does and you don’t have a working Backup anymore)
I’ll have to create a script for the Data / Files / Database to a 2nd NAS ?
I’ll have to create two scripts for the backup of the DietPi OS to an USB-drive and Harddisk?
/mnt/dietpi_userdata is only included when it’s on the same drive. If you moved it to an external drive, it’s not included and you need to create a separate script for that. You could use dietpi-sync and a similar approach for multiple backup rotation.
But for the database, a raw file backup is not what I would do, as it can only be reliably restored to the exact same MariaDB version then, theoretically a newer one as well, but I would not count on that. Instead do a regular database SQL dump, so that you can import it on any SQL database server and even browse/edit the SQL commands, if required.
I use this as daily cron job:
mysqldump --log-error=/var/log/nextcloud-db-backup.log nextcloud > /mnt/sda/ncdata/database-backups/$(date +%Y-%m-%d_%T).sql
Reminds me that I need to add an automated removal of old backups, currently it’s growing until I manually clean them up .
This is then mirrored again to a second backup drive, together with the Nextcloud data, to protect against data loss through drive crash. I know, a RAID tower would be better .
Hi,
no, this is not part of the dietpi-backup functionality. But you can create it yourself.
MichaIng
any hints for this removal?
how did you setup the mirrored backup to a second backup drive?
The following should work to keep 10 backups:
until (( $(find /mnt/sda/ncdata/database-backups/ -name '*.sql' | wc -l) < 11 ))
do
rm -v "$(find /mnt/sda/ncdata/database-backups/ -name '*.sql' | sort -n | head -1)"
done
I use simple rsync to backup all Nextcloud data afterwards. Could be dietpi-sync as well, but I wrote that script before using/joining DietPi .
rsync -aH --delete /mnt/sda/ncdata /mnt/sdb/backup/