I have a script that backups my Raspberry Pi
sudo dd bs=1M if=/dev/sda1 of=/home/pi/backup.img
zip -r /home/pi/backup/backup.zip /home/pi/backup.img
cp backup.zip ~/backup
I want to know how I can append the date to the backup.zip file, generated by the second line.
Any tips?
You can use command substitution to accomplish this.
You might also want to familiarize yourself with the date
components:
# Save the file name in a variable so we don't repeat ourselves
outfile="/home/pi/backup/backup.zip.$(date +%Y%m%d)"
sudo dd bs=1M if=/dev/sda1 of=/home/pi/backup.img
zip -r "${outfile}" /home/pi/backup.img
cp "${outfile}" ~/backup
The magic here is the $(date +%Y%m%d)
. This runs date +%Y%m%d
and captures the output which will be the current date in YYYYMMDD format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With