we will be using image utilities, found at the following link: https://forums.raspberrypi.com/viewtopic.php?t=332000
First create an SMB/CIFS share called 'backup'
-
install
sudo apt-get install cifs-utils
-
Add your credentials (i.e., your SMB user and password) to
nano ~/.storage_credentials
-
username=[username] #type it in as-is, without the [] password=[your password] #type it in as-is, without the []
-
chmod 0600 ~/.storage_credentials
so only the owner can read it -
create your local backup director by
cd to /etc/
andsudo mkdir backup
-
nano /etc/fstab
to mount your smb: -
#backups //[IP]/backup /home/[username]/backup cifs credentials=/home/[username]/.storage_credentials,x-systemd.automount,iocharset=utf8,rw,uid=1000,gid=1000,vers=3.0 0 0 #replace your [IP] and [username] in the entry above
-
mkdir ~/bin
-
Extract the image file utilities from the first post here into that /home/[user]/bin and make all items executable
-
cd /image-utils
sudo ./image-backup
- enter the name ``/mnt/backup/pi_backup.img
, then hit enter then
y` when prompted to start the backup. Wait patiently.
-
sudo nano backups
to create a backup script, add: -
#!/bin/bash BUFPATH="/mnt/backup/" BUFNAME="pi_backup_" BINPATH="/etc/local/bin/image-backup" CURDATE="$(date +%F)" BUSDATE="$(sed -n 's|^\(\S\+-\S\+\)-.*$|\1|p' <<< ${CURDATE})" CURFILE="$(ls ${BUFPATH}${BUFNAME}${BUSDATE}-??.img 2>/dev/null | sed -n "s|^\(${BUFPATH}${BUFNAME}${BUSDATE}-\S\+\.img$\)|\1|p")" if [ "${CURFILE}" = "" ]; then sudo "${BINPATH}" -i "${BUFPATH}${BUFNAME}${CURDATE}.img,,100" else sudo "${BINPATH}" "${CURFILE}" fi
-
crontab -e
, then add: -
0 4 * * * /home/[user]/backup