Comment on Where to start with backups?

<- View Parent
irmadlad@lemmy.world ⁨1⁩ ⁨day⁩ ago

Out of curiosity, how are you doing the drive imaging?

I wrote a script that is fired by a cron job once a month:

sudo nano /usr/local/bin/backup_drive.sh

spoiler

# Directory to store backups BACKUP_DIR=“/mnt/myhdd” # Drive to backup DRIVE=“/dev/sdX” # Create a timestamp TIMESTAMP=$(date +“%Y%m%d”) # Filename for the new image NEW_IMAGE=“$BACKUP_DIR/my_drive_image_$TIMESTAMP.img” # Create the image sudo dd if=$DRIVE of=$NEW_IMAGE bs=4M status=progress # Keep the last 3 images ls -tp $BACKUP_DIR/my_drive_image_*.img | grep -v ‘/$’ | tail -n +4 | xargs -I {} rm – {}

Make the script executable:

sudo chmod +x /usr/local/bin/backup_drive.sh

Create Cron:

sudo crontab -e

0 3 1 * * /usr/local/bin/backup_drive.sh

Verify cron:

sudo crontab -l

I’m sure it could be written differently or that there is a better way to do the imaging, but that is the extent of my notes, and it works for me.

source
Sort:hotnewtop