I often play around with little Bash scripts and Perl One-Liners in my quest to learn more. This particular script backs up specific data that I need when I reinstall an (Debian) OS.
I’ve got various versions and this is just a base (which you can add-to and play with). As always, with any code, especially Bash, there are a whole heap of ways to write backup scripts, both long and short, but this script is only intended to show newer users some basic commands, and to act as a template for further investigation.
#SIMPLE BASH BACKUP SCRIPT BY RICHS-LXH
#SAVES FILES TO A DATED DIR ON YOUR /STORAGE PARTITION
#ON SCREEN MESSAGE AND LOG CREATED
echo Backing up your data…
echo Backup started `date` >> ~/backuplog
#CREATE NECESSARY FILES
mkdir -p backups/`date +%Y%m%d`
mkdir -p backups/tmpdata/important/
#COPY FILES YOU WANT BACKED UP
sudo cp /etc/host* backups/tmpdata/important/
sudo cp /etc/X11/xorg.conf backups/tmpdata/important/
sudo cp /etc/network/interfaces backups/tmpdata/important/
#EMPTY THE TRASH BEFORE HOME BACKUP !!!
sudo rm -rf /home/rich/.local/share/Trash/files/*
#WAIT UNTIL IT HAS FINISHED REMOVING ALL THE TRASH
#COPY ENTIRE HOME DIR RECURSIVELY TO TMPDATA
sudo cp -a /home/rich backups/tmpdata/
#CD TO TMPDATA AND CREATE A COMPRESSED BACKUP TAR.GZ
tar -czf /storage/backups/`date +%Y%m%d`/bkp.tar.gz *
#REMOVE THE TEMPORARY DATA
sudo rm -rf tmpdata
#WRITE A LOG AND PRINT A MESSAGE
echo Backup Finished `date` >> ~/backuplog
echo All your data successfully backed up!