Simple shell script to backup selected directories

Couple months ago I published a short script to backup MySQL databases. Today I created simple shell script to backup selected directories.


# Parent backup directory
backup_parent_dir="/var/backup_server/$(hostname -s)"

# Directories to backup
backup_me="/etc /var/www /var/named /var/log"

# Check and create backup directory
backup_date=`date +%Y_%m_%d_%H_%M`
mkdir -p $backup_dir

# Perform backup
for directory in $backup_me
        archive_name=`echo ${directory} | sed s/^\\\/// | sed s/\\\//_/g`
        tar pcfzP ${backup_dir}/${archive_name}.tgz ${directory} 2>&1 | tee > ${backup_dir}/${archive_name}.log
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland