1

How would I go about compressing a list of directories into separate archives? I have read solutions that just archive all the directories within a given dir, but there are some I want to skip. Perhaps an easier way would be to define the directories I DO NOT want to archive.

This is for backup purposes so if incremental archiving can be easily implemented that would be a huge plus. Unfortunately rsync is not an option for me.

Alternatively a script such as AutoMySQLBackup but for directories would be a great pay dirt for me.

bskool
  • 161
  • 1
  • 1
  • 8

1 Answers1

1

I came up with this. It looks inside a defined directory, archives all the directories within to their own separate files and gives them a name based off the source directory name & date of script execution.

#!/bin/bash

#START
TIME=`date +%Y-%m-%d_%Hh%Mm`     # Append date and time to backup file
SRCDIR=/srv                      # Location of directories to backup
DESDIR=/srv/backup               # Destination of backup files
EXCLUDE=exclude.txt  # File which defines what to exclude from archiving

for dir in $SRCDIR/*/
do
  base=$(basename "$dir")
  tar -cpzf $DESDIR/$base-$TIME.tar.gz $dir
done
#END

The problem with this? Unless the destination directory is outside the source directory, it will keep archiving the backup folder where the previous archive/s was/were already created; as the $EXCLUDE variable is not being used.

bskool
  • 161
  • 1
  • 1
  • 8