Running commands at first boot only / Backing up dietpi-systems correctly

Hi there,

I back up my system with the following commands (from a running dietpi-setup) remotely:

#some ops before the backup
sshpass -p $password ssh root@$ip "sudo dd if=/dev/mmcblk0 bs=1M status=progress | pigz -" | dd of=largebackup.gz
#some ops after the backup
pv largebackup.gz | pigz -d -c > Raspi.img

sudo -a Raspi.img #
pv Raspi.img | pigz -c > small_backup.gz

I am doing this for years now on original raspbian images with great success. But dietpi is better for my purpose then the original raspbian =)

The small_backup.gz is just about 1/5 of the size of large_backup.gz and I can do on-the-fly operations just before and just after a backup.

I am open for a better approach, but basically this is not my question.

The questions are:

  • I need to run certain commands (i.e. systemctl enable dietpi-fs_partition_resize ) on the first boot of a backed up system only. How would I do this?

  • If there is a way to “reset” a diet-pi system before backing it up as an image this would also be a great approach since the system would behave like on the VERY first boot of an original dietpi-image. How would I do this?

  • Is there a “how do I back up my dietpi-system” guide?

Thanks for your help!


An idea would be to enable the service before creating the backup. This way it will be part of the backup automatically. Once backup completed, service can be disabled again.

Theoretically you could run our install script. This way, system will be set back close to an original status. However some user/individual configuration files might survive. But this will clear all apps installed. In this case it might be easier to flash a new image, isn’t it?

We don’t have a real guide. There is a blog post talking about backup possibilities DietPi-Backup in an multi-device environment - DietPi blog but I guess this is not what you are looking for.