Problem with tar in a backup script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with tar in a backup script
# 1  
Old 12-17-2009
Problem with tar in a backup script

I had an idea of very-very easy bacup script that packs ALL of the files in current dir (including the subfulders and with spaces in name), packs them with tar+gz and moves to a directory. I'm using Cywin under WinXP.
But I have a problem with tar. When I do in a single line

"tar -rf "backup.tar" "somefile1.txt"; "tar -rf "backup.tar" "somefile2.txt";

It says that I need -M for multiple archives (?).
That's my code:

Code:
#!/bin/sh
BackUpDir="/cygdrive/D/Backup5"
if ([ $1 ]) then
  BackUpDir=$1
fi
if ([ ! -d $BackUpDir ]) then
  mkdir -pv $BackUpDir
fi
ArchiveName="$BackUpDir/"`date +"%d.%m.%y(%H.%M)"``dirs | sed 's!^\(/\?.*\)*/\(.*\)$!\2!g'`".tar"
PackCommand=`find -type f -regex ^.*$ | sed 's!^\(.*\)$!tar -M -rf \"__tmp.tar\" \"\1\"'!g`
$PackCommand
rm "__tmp.tar" $ArchiveName
gzip $ArchiveName


Last edited by pludi; 12-17-2009 at 07:43 AM.. Reason: code tags, please...
# 2  
Old 12-17-2009
Why do you have so many double quotes in that line? Try without them maybe. Does it work with -M? In you code you are using -M. What happens if both tar's are being executed on separate lines?
I did not check your sed's but tar takes anything from the starting directory for example, that you want even files that have blanks in etc. Not sure if cygwin's tar is making a difference.
# 3  
Old 12-17-2009
I've did some experiments with masks for tar - tar -cd "$ArchiveName" * works fine and includes subdirectories as well.
Anyway, that's a final verusion of my script. It bacups the current folder, including names with spaces and subdirectories.

Quote:
#!/bin/sh
BackUpDir="/cygdrive/D/Backup5"
if ([ $1 ]) then
BackUpDir=$1
fi
if ([ ! -d $BackUpDir ]) then
mkdir -pv $BackUpDir
fi
ArchiveName="$BackUpDir/"`date +"%d.%m.%y(%H.%M)"``dirs | sed 's!^\(/\?.*\)*/\(.*\)$!\2!g'`".tar"
tar -cf "$ArchiveName" *
gzip $ArchiveName
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Backup and restore using tar

This will be covered elsewhere im sure but i just cant seem to find my exact issue. I want to backup my systems using tar, command is: tar -cjpf /backup /bin /etc /home /opt /root /sbin /usr /var /bootWhen i include the / directory it also tar's the /lib /sys /proc /dev filesystems too (and... (8 Replies)
Discussion started by: Tommyk
8 Replies

2. Shell Programming and Scripting

Backup script to split and tar files

Hi Guys, I'm very new to bash scripting. Please help me on this. I'm in need of a backup script which does the ff. 1. If a file is larger than 5GB. split it and tar the file. 2. Weekly backup file to amazon s3 using s3rsync 3. If a file is unchanged it doesn't need to copy to amazon s3 ... (4 Replies)
Discussion started by: ganitolngyundre
4 Replies

3. Shell Programming and Scripting

Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr

Hello, Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code: tar $TAR_PARAMS $ARCHIVE_FILE $EXCLUDE $BACKUP_STARTwith... (6 Replies)
Discussion started by: ilnar
6 Replies

4. Shell Programming and Scripting

lvm/tar/rsync backup script feedback/criticism

I have written a shell script to perform backups using tar, rsync and optionally utilise lvm snapshots. The script is not finished but is in a working state and comments/descriptions are poor. I would greatly appreciate any criticism and suggestions of the script to help improve my own learning... (0 Replies)
Discussion started by: jelloir
0 Replies

5. Shell Programming and Scripting

Please : Script Backup Problem

I have script but not work.. ===================================== #!/bin/bash # backup Backup_Dirs="/home/test" Backup_Dest_Dir=/tmp Backup_Date=`date +%b%d%y` #Create Backup tar cvzf $Backup_Date.tar.gz $Backup_Dirs $Backup_Dest_Dir ====================================== What's... (1 Reply)
Discussion started by: mbah_jiman
1 Replies

6. Shell Programming and Scripting

Problem with backup script

Hi, Following is the script I made for backing up Cpanel server. ================================================ #! /bin/bash rsync -raopguzl --delete --exclude "*.tar.gz" --progress --delete-excluded root@$hostname:/$otherdir/$i/ /mnt/iscsi/$hostname/home/$i done ... (6 Replies)
Discussion started by: mohitmoudgil
6 Replies

7. UNIX for Dummies Questions & Answers

Backup with tar

Hi friends, I am planning to backup my Solaris Servers to SAN storage using tar. Also palnning to automate the job using Crontab. Can anyone advise how to make the date change automatically everyday for backup. Pls correct me if I am wrong. Thanks (7 Replies)
Discussion started by: solaris5.10
7 Replies

8. Shell Programming and Scripting

Diff. Backup Script Using TAR. Should be simple.

I'm specifically trying to find help or insight on using the --incremental ('-G') option for creating a tar. Please resist the urge to tell me to use --listed-incremental ('-g') option. That's fairly well documented in the GNU tar manual. GNU tar 1.19 This is what the manual does say in section... (0 Replies)
Discussion started by: protienplant
0 Replies

9. UNIX for Dummies Questions & Answers

Tar backup

I am trying to do a full system backup using tar. It then after maybe 12 or so hours comes up with tar: write error: unexpected EOF. I have thoroughly cleaned the drive and tried to use a different drive but it still gives me this error. Can someone help. I am on solaris 8. (1 Reply)
Discussion started by: TMashie
1 Replies

10. UNIX for Advanced & Expert Users

tar backup

Hi all, I would like to append list of files to already taken tar backup file. can anybody help? last month backup : cd /accounts/11 tar -cvf monthback.tar * Now I want to add /accounts/12 to monthback.tar is it possible? Krishna (1 Reply)
Discussion started by: krishna
1 Replies
Login or Register to Ask a Question