Re: tar - explicit spanning
Adam Blomberg wrote:
> Essentially, I want to archive a large directory into 2.2 Gbyte tarballs
> which are "spanning" in nature. I have an 18 Gbyte directory tree that I
> want to compress into a set of 2.2 Gbyte archives so that I can copy the
> individual tarballs onto separate DVD-RAM media later. It appears that
> the -M (multple) flag only works properly when you actually run out of
> space on the medium you are archiving to. Is there a way to force tar to
> create iterative files in a specified size?
#!/bin/sh -e
# Kite short term backup script. Back up directories to a spare hard drive.
# This script is complicated a lot by having to ensure that the files arn't
# bigger than 2 gb. It uses multi-volume tar files.
# Configuration section.
DIRS="home var etc root usr/local"
BACKUPDIR=/mirror/kitenet/`hostname`
VERBOSE=""
# This is a bit smaller than 1 cd. It could be up to 2 gb.
VOLUME_SIZE=655360
NEXTFILE=.next
# If this is set, we are being called to change volumes.
if [ "$BACKUP_VOLUME" ]; then
if [ -e $NEXTFILE ]; then
n=`cat $NEXTFILE`
else
n=1
fi
mv -f $BACKUP_VOLUME $BACKUP_VOLUME.$n
echo `expr 1 + $n` > $NEXTFILE
else
# Paricular directories to backup can be speicifed, or the
# whole list is used.
if [ ! "$1" ]; then
set -- $DIRS
fi
if [ "$VERBOSE" ]; then
TAR_VERBOSE=-v
fi
if [ ! -x "$BACKUPDIR" ]; then
echo "$0: $BACKUPDIR does not exist" >&2
exit 1
fi
# Make sure that this script is on the path, even if it was called
# relatively, before cding, so we can call ourselves later.
PATH=$PATH:`pwd`
cd $BACKUPDIR
# Lock directory.
if ! mkdir .backup_in_progress; then
echo "$0: another backup is already in progress" >&2
exit 2
fi
# Do the backups.
for dir; do
rm -f $NEXTFILE
BACKUP_VOLUME=`echo $dir | sed s:/:_:g`.tar
# So we can see this when asked to change volumes.
export BACKUP_VOLUME
# Move all old files out of the way.
if [ ! -d old ]; then
mkdir old
fi
mv $BACKUP_VOLUME.* old 2>/dev/null || true
# Use ourselves to change volumes.
if tar cf $BACKUP_VOLUME /$dir --preserve $TAR_VERBOSE -L $VOLUME_SIZE -F $0; then
# Move the last file.
$0
rm -rf old
else
echo "$0: error backing up $dir" >&2
fi
rm -f $NEXTFILE
done
rm -f $NEXTFILE
rmdir .backup_in_progress
fi
Reply to: