How to combine Backup and Sync in one cron script

Hi fellas,

I was wondering if it was possible to combine a backup with a sync.

I would like to do both one after the other via a script (unattended) launched daily or weekly.

I am aware there are plans to merge dietpi-backup and -sync but as this isnt there yet, I am looking for other ways to backup my dietpi and sync the result from one HDD to another.

I am also aware of the option to enable daily sync within the options of the dietpi-sync but I am afraid that this will collide as cron jobs are triggered in parallel. So the backup via a script within cron.daily (Taken from another forum post) might run at the same time as sync which might lead to incorrect results.

I guess my question is can I combine dietpi-backup and dietpi-sync in one script I put into cron.daily?
I tried but the logfile I try to write to doesnt update which makes me think I am overseeing something and the commands cannot bei combined easily.

Thanks in advance!

You could add both command calls to the same crontab/script, like:

#!/bin/dash
/DietPi/dietpi/dietpi-backup 1 || exit 1
/DietPi/dietpi/dietpi-sync 1 || exit 1
exit 0

So the correct order and no concurrency is guaranteed.
Daily sync of course needs to be disabled then for dietpi-sync.

Excellent.

I will give this a try a report back.

Thank you very much in advance.

Test was successful.

Works like a charme. :slight_smile:

Hello, I want to expand a little bit more the initial question, if possible.

Both dietpi-backup and dietpi-sync tools are using daily cron to be scheduled.

After reading the thread I checked the content of /etc/cron.daily/dietpi and I found the following order for the mentioned tools:

[...]
	# DietPi-Backup daily
	if [[ -f '/boot/dietpi/.dietpi-backup_settings' ]] && grep -q '^[[:blank:]]*DAILY_BACKUP=1' /boot/dietpi/.dietpi-backup_settings
	then
		/boot/dietpi/dietpi-backup 1
	fi
	#----------------------------------------------------------------
	# DietPi-Sync daily
	if [[ -f '/boot/dietpi/.dietpi-sync_settings' ]] && grep -q '^[[:blank:]]*SYNC_CRONDAILY=1' /boot/dietpi/.dietpi-sync_settings
	then
		/boot/dietpi/dietpi-sync 1
	fi
[...]

Also on my DietPi I want to use dietpi-backup with a target disk A and then I want to copy the content of disk A to disk B with dietpi-sync.

Can I assume that dietpi-backup and dietpi-sync are executed sequentially ‘by design’ and rely on this behaviour for my purpose?

Thank you,
all the best for the new year

theoretically yes. However, it would be better to follow @MichaIng suggestion creating an own cron job. Simply to prevent a failed backup from being copied via sync.

Thank you @Joulinar :slight_smile:

If I get the suggestion correctly, to use custom cron job to combine backup and sync, I’ve to disable both cron jobs managed by DietPi itself.

Am I right?

correct

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.