Results 1 to 6 of 6
I made my first backup script. It tars three directories.
/etc -> /media/Storage/backup/etc.tar.bz2
/root -> /media/Storage/backup/home/root.tar.bz2
/home/matthew -> /media/Storage/backup/home/matthew.tar.bz2
etc.tar.bz2 and root.tar.bz2 come out ok, but something happens with matthew.tar.bz2. ...
- 01-01-2010 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 45
[SOLVED] faulty, but not corrupted .tar.bz2 when using tar from bash script
I made my first backup script. It tars three directories.
/etc -> /media/Storage/backup/etc.tar.bz2
/root -> /media/Storage/backup/home/root.tar.bz2
/home/matthew -> /media/Storage/backup/home/matthew.tar.bz2
etc.tar.bz2 and root.tar.bz2 come out ok, but something happens with matthew.tar.bz2. when i run 'tar -xjf matthew.tar.bz2' my system hangs for a minute or so. switching terminals still works, but any new process won't run... tar doesn't report the file as possibly corrupted, only an unrecoverable error.
I get this from bzip2
my script is below, is the problem in the script or is bzip2 compressing a file it shouldn't? i made the exclude list to contain any open files in useCode:bzip2: I/O or other error, bailing out. Possible reasons follow: bzip2: Input/output error Input file = (stdin) Output file = (stdout) tar: unexpected EOF tar: unexpected EOF tar: unrecoverable error
update: if i comment out all lines except for variables, mounting, and "tar ... $HOMEDIR/matthew.tar.bz2 /home/matthew", the archive is fine
Code:#!/bin/sh THISPARTITION="no" UNMOUNTATEND="yes" FSTYPE="ext2" PARTITION="/dev/hda4" MOUNTPOINT="/media/Storage" TARFLAGS="-pcjf" BROADCASTTTYS="/dev/tty1 /dev/tty2 /dev/tty3 /dev/tty4" matthewEXCLUDE="--exclude-from /root/.backup_exclude" # NOARCHIVE="no" # if [ $THISPARTITION != yes ]; then echo "* mounting $FSTYPE partition $PARTITION on $MOUNTPOINT" if [ -e $MOUNTPOINT/Library ]; then umount -t $FSTYPE $PARTITION fi sleep 1 mount -t $FSTYPE $PARTITION $MOUNTPOINT fi for i in /dev/tty1 /dev/tty2 /dev/tty3 /dev/tty4 /dev/tty5; do echo "backup started" > $i done if [ -e /dev/pts/0 ]; then for i in /dev/pts/*; do echo "backup started" > $i done fi sleep 5 if [ $NOARCHIVE != yes ]; then CONFDIR="/media/Storage/backup/etc" HOMEDIR="/media/Storage/backup/home" etcbz="$CONFDIR/etcbk.tar.bz2" if [ -e $etcbz ]; then mv $etcbz $etcbz.old cp /home/matthew/.xinitrc /home/matthew/.xinitrc.bk echo "OLD FILE: moved $etcbz -> $etcbz.old" printf "tar now archiving /etc to $etcbz\n" tar $1 $TARFLAGS $etcbz /etc else # FOR NEW SYSTEM echo "tar creating $etcbz from your /etc directory" tar $1 $TARFLAGS $etcbz /etc fi roothomebz="$HOMEDIR/root.tar.bz2" if [ -e $roothomebz ]; then mv $roothomebz $roothomebz.old echo "OLDFILE: moved $roothomebz -> $roothomebz.old" printf "tar now archiving /root to $roothomebz\n" tar $1 $TARFLAGS $roothomebz /root else # FOR NEW SYSTEM echo "tar creating $roothomebz from your /root directory" tar $1 $TARFLAGS $roothomebz /root fi for i in $BROADCASTTTYS; do echo "/root backup done" > $i done matthewhomebz="$HOMEDIR/matthew.tar.bz2" if [ -e $matthewhomebz ]; then mv $matthewhomebz $matthewhomebz.old echo "OLDFILE: moved $matthewhomebz -> $matthewhomebz.old" printf "tar now archiving /home/matthew to $matthewhomebz\n" printf "excluding:\n" echo "$(cat /root/.backup_exclude)" tar $1 $matthewEXCLUDE $TARFLAGS $matthewhomebz /home/matthew else echo "tar creating $matthewhomebz from your /home/matthew directory" tar $1 $matthewEXCLUDE $TARFLAGS $matthewhomebz /home/matthew fi for i in $BROADCASTTTYS; do echo "/home/matthew backup done" > $i done if [ -e /dev/pts/0 ]; then for i in /dev/pts/*; do echo "/home/matthew backup done" > $i done fi sleep 2 # end NOARCHIVE if fi if [ $UNMOUNTATEND = yes ]; then echo "* unmounting $PARTITION" umount -t $FSTYPE $PARTITION else echo fi for i in $BROADCASTTTYS; do echo "backup's done" > $i done if [ -e /dev/pts/0 ]; then for i in /dev/pts/*; do echo "backup's done" > $i done fiLast edited by muton; 01-02-2010 at 07:15 PM. Reason: update
- 01-03-2010 #2Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
One comment : why do you include $matthewEXCLUDE in the tar command when archiving /home/matthew ?
One suggestion : add a sync command before unmounting.
Don't know if it will solve your problem.
- 01-03-2010 #3Just Joined!
- Join Date
- Jul 2009
- Posts
- 45
i thought the problem may be open file in use, tar was reporting "file changed as we read it". so I used lsof and made a list to be used with --exclude-from that contained any files that were in use when i had all my programs running. $matthewEXCLUDE includes this list.
i tried using sync, still the same problem. thanks for the suggestion though.
- 01-04-2010 #4Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
But $matthewEXCLUDE points to /root/.backup_exclude and not to /home/matthew/.backup_exclude, and it is used while archiving /home/matthew.
This will not solve the problem though.
- 01-05-2010 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 45
yeah i moved it, I thought it may have been causing problems by being in /home/matthew. sorry about that
- 01-07-2010 #6Just Joined!
- Join Date
- Jul 2009
- Posts
- 45
when $1 was empty, it caused a double blank and tar does not like this coming before --exclude-from. I moved $1 to after $matthewEXCLUDE, fixed.


