Backup script in cron.daily

Having issues with your DietPi installation, or, found a bug? Post it here.
Lycidias
Posts: 7
Joined: Mon Oct 26, 2020 11:01 am

Backup script in cron.daily

Post by Lycidias »

Hello,

I created a backup Script on my raspberry pi 4 and placed it in /etc/cron.daily and named it "backup". I also Set the cron.daily runtime.

But the Script won't run. When i Start it via terminal it just works. Can you help me?

Thank you very much :)

The permissions i set:

Code: Select all

-rwxr-xr-x 1 root root 169 Oct 26 10:39 /etc/cron.daily/backup
The Script itself:

Code: Select all

#!/bin/bash
#
rm -rf /mnt/hdd1/backup/dietpi-backup_old
cd /mnt/hdd1
mv /mnt/hdd1/backup/dietpi-backup "/mnt/hdd1/backup/dietpi-backup_old"
/boot/dietpi/dietpi-backup 1
User avatar
Joulinar
Posts: 2572
Joined: Sat Nov 16, 2019 12:49 am

Re: Backup script in cron.daily

Post by Joulinar »

Hi,

many thanks for your message. You could perform a dry-run using run-parts --test /etc/cron.daily/. This should display all scripts that's going to be executed on daily basis.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Lycidias
Posts: 7
Joined: Mon Oct 26, 2020 11:01 am

Re: Backup script in cron.daily

Post by Lycidias »

Thank you very much.

Code: Select all

root@xxx:~# run-parts --test /etc/cron.daily/
/etc/cron.daily//apt-compat
/etc/cron.daily//backup
/etc/cron.daily//dietpi
/etc/cron.daily//dpkg
/etc/cron.daily//passwd
/etc/cron.daily//samba
root@xxx:~#
Seems like it should work. But the backup was not created last night. When i run the Script via terminal the backup is working...
User avatar
Joulinar
Posts: 2572
Joined: Sat Nov 16, 2019 12:49 am

Re: Backup script in cron.daily

Post by Joulinar »

you can have a look to journalctl -u cron.service and check for the time frame the daily jobs should be executed. Maybe there are messages related to your script.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Lycidias
Posts: 7
Joined: Mon Oct 26, 2020 11:01 am

Re: Backup script in cron.daily

Post by Lycidias »

I think i found the issue... I excluded cron service from dietpi autocontrol... :roll: :lol:

The Script is now executed daily. Many Thanks! :-)
User avatar
Joulinar
Posts: 2572
Joined: Sat Nov 16, 2019 12:49 am

Re: Backup script in cron.daily

Post by Joulinar »

ah ok, the cron.service was not started, right?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Lycidias
Posts: 7
Joined: Mon Oct 26, 2020 11:01 am

Re: Backup script in cron.daily

Post by Lycidias »

Joulinar wrote: Tue Oct 27, 2020 10:14 am ah ok, the cron.service was not started, right?
Exactly, i think so :-D
User avatar
Joulinar
Posts: 2572
Joined: Sat Nov 16, 2019 12:49 am

Re: Backup script in cron.daily

Post by Joulinar »

clear, good you found it :)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 2422
Joined: Sat Nov 18, 2017 6:21 pm

Re: Backup script in cron.daily

Post by MichaIng »

If you want to keep cron running through DietPi updates/installs/backups and such, hence exclude it from DietPi control, enable it to be started by systemd instead: systemctl enable --now cron
But while there are cases where servers/services need to run while you still want to install something, cron is really the last thing I'd consider important enough, while it's important to be generally running as used by many 3rd party software to do their maintenance jobs.
Lycidias
Posts: 7
Joined: Mon Oct 26, 2020 11:01 am

Re: Backup script in cron.daily

Post by Lycidias »

MichaIng wrote: Thu Oct 29, 2020 3:55 pm If you want to keep cron running through DietPi updates/installs/backups and such, hence exclude it from DietPi control, enable it to be started by systemd instead: systemctl enable --now cron
But while there are cases where servers/services need to run while you still want to install something, cron is really the last thing I'd consider important enough, while it's important to be generally running as used by many 3rd party software to do their maintenance jobs.
Thanks, that would be useful for samba :) can i only Set services that are shown in dietpi Service control?

For anyone who is interested in, my updated basic backup Script for cron.weekly:

Code: Select all

#!/bin/bash
#
rm -rf /mnt/hdd1/backup/dietpi-backup_4
mv /mnt/hdd1/backup/dietpi-backup_3 "/mnt/hdd1/backup/dietpi-backup_4"
mv /mnt/hdd1/backup/dietpi-backup_2 "/mnt/hdd1/backup/dietpi-backup_3"
mv /mnt/hdd1/backup/dietpi-backup "/mnt/hdd1/backup/dietpi-backup_2"
/boot/dietpi/dietpi-backup 1
The script keeps the 4 latest backups, a whole month on my usb hard disk mounted as /hdd1.
Post Reply