Linux: Simple Arch Linux Backup Script

To create regular backups of my important Konfigurationserzeichnisse I created a little backup script. It is very simple, but does the job. Currently the script has the following functionality:

  1. Copy the configuration folders and files in the home directory. This Start with a point .
  2. Creates a software list of all installed applications
  3. It is the pacman database secured

After a new installation or a system crash can by this backup to restore much of the functionality of the original system. The configuration data are available and by yaourt the software can be installed via list which saves a lot of time. The script uses the snapshot process as we know it from Apple's Time Machine backup. A nice benefit of this solution is the efficient usage of space. For this purpose, working with rsync Hardlinks. The script linked all unchanged files in the current backup folder and copied added new and changed files. So can jump to each snapshot and storage growth always corresponds to the new or modified files. The script is far from complete, but should be expanded to include, for example paths enter interactively, Read configuration from a file or to run the script with input parameters. To simplify the backup and restore more is also a script planned Restore.

#!/bin/bash
echo -e "#####################################
# Welcome to my backup script #
# for private purposes. The #
# script backups the home config #
# dirs and a software list of #
# pacman and yaourt #
#####################################\n\n"

#echo -e "# THE FIRST THING TO DO IS TO SPECIFY THE BACKUP DESTINATION #" # Define the backup location
#read -e -p "backup path:" bak_dest
#echo -e "\n\n# IS THIS THE CORRECT PATH TO STORE YOURE BACKUP? #"
#echo $bak_dest
#read -p "# PRESS ENTER TO CONFIRM... #"

####################
# define variables #
####################

volume="/media/backintime_nas"
bak_dest=/media/backintime_nas/micha_bak/ # hardcoded path
heute=$(date +%Y-%m-%d_%H-%M-%S) # date variable
bak_source='/home/micha/' # pathn to backup directory
declare -a bak_directories=('.[^.]*') # Define only hidden files and folders to backup
bak_items=("${bak_directories[@]/#/$bak_source}") # Put directory name and path together
bak_allitems=${bak_items[@]} # full path is goin into an array so we can iterate through

#-----------------------------------------------------------------------------------------------------------------------------------------------------------

echo -e "##############################################
# check if backup destination aleady mounted #
##############################################"

sleep 3
if mount|grep $volume; then # check if destination is already mounted
echo "mounted"
else
mount /media/backintime_nas
fi

#-----------------------------------------------------------------------------------------------------------------------------------------------------------

echo -e "\n\n###################
# do the backup #
###################"
sleep 3
rsync -avzh --delete ${bak_allitems} ${bak_dest}${heute} --link-dest="${bak_dest}last/" # start the backup with hard links to save time and space
# a = archive; v = verbose; z = compress during transfer; h = human readable; P = progress (not human)
rm -rf ${bak_dest}last # Delete the reference to latest backup
ln -s "${bak_dest}${heute}" "${bak_dest}last" # Actualize and point the new softlink to the last backup

#-----------------------------------------------------------------------------------------------------------------------------------------------------------

echo -e "\n\n###############################
# SAVING THE PACMAN DATABASE #
###############################"

sleep 3
tar -cjf ${bak_dest}${heute}/pacman_database.tar.bz2 /var/lib/pacman/local # Backup the pacman database

#-----------------------------------------------------------------------------------------------------------------------------------------------------------

echo -e "\n\n#################################
# NOW GENERATE THE PACMAN LISTS #
#################################"

sleep 3
pacman -Qqe | grep -v "(pacman -Qqm)" > ${bak_dest}${heute}/amiga_$(date +%F)_pkglist-off.txt # Save installed software list

ME

Leave a Reply

Your email address will not be published. Required fields are marked *

Consent to the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.