Automate dietpi-backup
Automate dietpi-backup
Is it possible to do this from script/cron job?
John
John
Re: Automate dietpi-backup
Hi @johnvick,
yes this should be possible via dietpi-backup 1, which takes the settings chosen via dietpi-backup before. However we do some automated check for interactive shell, which appears to work fine for cron and systemd units, but in case the command hangs, please add G_USER_INPUT=0 to force recognition of non-interactive shell. Full command would be then:
G_USER_UNPUT=0 dietpi-backup 1
@Fourdee
As for G_WHIP_YESNO in non-interactive shells "yes" is chosen, right now insufficient free space is ignored. We should change this. Possible:
- Always ask G_WHIP_YESNO in a way, that "yes" (return 0) is the safest/most compatible answer.
- As by default "no" is selected, do it the other way round and chose "no" if non-interactive.
- Actively chose default answer/input in code and use this as non-interactive result as well.
yes this should be possible via dietpi-backup 1, which takes the settings chosen via dietpi-backup before. However we do some automated check for interactive shell, which appears to work fine for cron and systemd units, but in case the command hangs, please add G_USER_INPUT=0 to force recognition of non-interactive shell. Full command would be then:
G_USER_UNPUT=0 dietpi-backup 1
@Fourdee
As for G_WHIP_YESNO in non-interactive shells "yes" is chosen, right now insufficient free space is ignored. We should change this. Possible:
- Always ask G_WHIP_YESNO in a way, that "yes" (return 0) is the safest/most compatible answer.
- As by default "no" is selected, do it the other way round and chose "no" if non-interactive.
- Actively chose default answer/input in code and use this as non-interactive result as well.
Re: Automate dietpi-backup
Hi @MichaIng
Thanks for the help - dietpi-backup 1 works from the command line but putting it in a simple script fails:
Gives an error message
./backup.sh: line 3: dietpi-backup: command not found.
The reason for trying to set this up is that my backup is never recent enough
John
Thanks for the help - dietpi-backup 1 works from the command line but putting it in a simple script fails:
Code: Select all
#!/bin/bash
#
dietpi-backup 1
./backup.sh: line 3: dietpi-backup: command not found.
The reason for trying to set this up is that my backup is never recent enough

John
Re: Automate dietpi-backup
@johnvick
Ah sorry, our aliases are not present within scripts, use
/DietPi/dietpi/dietpi-backup 1
Ah sorry, our aliases are not present within scripts, use
/DietPi/dietpi/dietpi-backup 1
Re: Automate dietpi-backup
This works nicely
:
Copies the old backup with the current date appended (maybe not the best solution but it allows you to have multiple backups) and then creates a new one.
John
Code: Select all
#!/bin/bash
#
cd /mnt/usb_2
cp -aR /mnt/usb_2/dietpi-backup "/mnt/usb_2/dietpi-backup-$(date +"%m-%d-%y-%r")"
/DietPi/dietpi/dietpi-backup 1
Copies the old backup with the current date appended (maybe not the best solution but it allows you to have multiple backups) and then creates a new one.
John
Re: Automate dietpi-backup
Better solution:
Code: Select all
#!/bin/bash
#
cd /mnt/usb_2
mv /mnt/usb_2/dietpi-backup "/mnt/usb_2/dietpi-backup-$(date +"%m-%d-%y-%r")"
/DietPi/dietpi/dietpi-backup 1
Re: Automate dietpi-backup
@johnvick
Nice one
. I do it a bid similar for my MariaDB dumps, although I don't like that it grows unlimited until you clean up by yourself.
Another way is adding a count number to file name, always removing a defined max number and incrementally increase the earliers files count before doing fresh backup:
Thought about implementing something like into dietpi-backups itself.
Nice one

Another way is adding a count number to file name, always removing a defined max number and incrementally increase the earliers files count before doing fresh backup:
Code: Select all
MAX_BACKUPS=10
cd /mnt/usb_2
if [[ -d dietpi-backup ]]; then
rm dietpi-backup-$MAX_BACKUPS
for ((i=$MAX_BACKUPS-1;i>1;i--); do
mv dietpi-backup-$i dietpi-backup-$( (( $i+1 )) )
done
mv dietpi-backup dietpi-backup-2
fi
/DietPi/dietpi/dietpi-backup 1
Re: Automate dietpi-backup
Nice one @MichaIng I'll adopt your method.
Thanks, John
Thanks, John
Re: Automate dietpi-backup
I get this error - any ideas? @MichaIng
I'm not very good at scripts or coding!
I'm not very good at scripts or coding!
Code: Select all
[email protected]:/home/john/scripts# ./backup.sh
./backup.sh: line 5: syntax error near `;'
./backup.sh: line 5: ` for ((i=$MAX_BACKUPS-1;i>1;i--); do'
Re: Automate dietpi-backup
@johnvick
Forgot the second closing parenthesis: ((...i--));
Also mv inside same folder should really just rename files, but to assure you could add time output around the loop to check if it really just takes a second or so:
echo $(date +'%H:%M:%S')
Would be nice to keep timestamps inside the file names actually for better archiving/review, but then there is a safe way needed to assure that really the oldest file is removed. Will try around a bid
.
I opened issue on github, would like to have this implemented into DietPi-Backup: https://github.com/Fourdee/DietPi/issues/1785
Forgot the second closing parenthesis: ((...i--));
Also mv inside same folder should really just rename files, but to assure you could add time output around the loop to check if it really just takes a second or so:
echo $(date +'%H:%M:%S')
Would be nice to keep timestamps inside the file names actually for better archiving/review, but then there is a safe way needed to assure that really the oldest file is removed. Will try around a bid

I opened issue on github, would like to have this implemented into DietPi-Backup: https://github.com/Fourdee/DietPi/issues/1785