Automate dietpi-backup

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
User avatar
MichaIng
Site Admin
Posts: 2507
Joined: Sat Nov 18, 2017 6:21 pm

Re: Automate dietpi-backup

Post by MichaIng »

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.
hemertje
Posts: 10
Joined: Mon Dec 21, 2020 11:35 am

Re: Automate dietpi-backup

Post by hemertje »

I assume that this

Code: Select all

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?
hemertje
Posts: 10
Joined: Mon Dec 21, 2020 11:35 am

Re: Automate dietpi-backup

Post by hemertje »

MichaIng wrote: Sun Jan 03, 2021 4:25 pm 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.
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?
User avatar
MichaIng
Site Admin
Posts: 2507
Joined: Sat Nov 18, 2017 6:21 pm

Re: Automate dietpi-backup

Post by MichaIng »

/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:

Code: Select all

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 :lol:.

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 ;).
User avatar
Joulinar
Posts: 3284
Joined: Sat Nov 16, 2019 12:49 am

Re: Automate dietpi-backup

Post by Joulinar »

Hi,

no, this is not part of the dietpi-backup functionality. But you can create it yourself.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
hemertje
Posts: 10
Joined: Mon Dec 21, 2020 11:35 am

Re: Automate dietpi-backup

Post by hemertje »

MichaIng wrote: Sun Jan 03, 2021 5:20 pm
Reminds me that I need to add an automated removal of old backups, currently it's growing until I manually clean them up :lol:.

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 ;).
@MichaIng

any hints for this removal?

how did you setup the mirrored backup to a second backup drive?
User avatar
MichaIng
Site Admin
Posts: 2507
Joined: Sat Nov 18, 2017 6:21 pm

Re: Automate dietpi-backup

Post by MichaIng »

The following should work to keep 10 backups:

Code: Select all

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 ;).

Code: Select all

rsync -aH --delete /mnt/sda/ncdata /mnt/sdb/backup/
Post Reply