Sponsored Content
Top Forums Shell Programming and Scripting Help with adding to tar filenames Post 302380857 by Swinton on Wednesday 16th of December 2009 11:24:08 AM
Old 12-16-2009
Help with adding to tar filenames

Hi there, i have been working on a backup script and have it just about working, the only problem im left with is that my filenames for my backups are all the same are replacing one another when backing up.

currently i have
BACKUP_FILE=backup_$(date +%d%m%y).tgz
but would like something like
BACKUP_FILE=backup_(filename)_$(date +%d%m%y).tgz
to help with identification

any help is appreciated and my code is posted below.
Code:
    #!/bin/bash
   
  clear
   
  VALID_PATH=0
  BACKUP_FILE=backup_$(date +%d%m%y).tgz
  BACKUP_DIR=.backup/
   
  [[ ! -d $BACKUP_DIR ]] && mkdir -p $BACKUP_DIR
  echo 1 Perform A Directory Backup
  echo 2 Perform A File Backup
  echo 3 Restore From Backup
  echo 4 Exit Program
   
  read OPTION
   
  case $OPTION in
   
  "1") echo You Selected Option 1
  echo Please Enter The Directory You Wish To Backup
  read SOURCE
   
  while [[ $VALID_PATH -eq 0 ]]
   
  do
   
  if [[ -d "$SOURCE" ]]; then
          VALID_PATH=1
          BACKUP_FILE="$BACKUP_DIR""$BACKUP_FILE"
  else
          echo This Path Is Invalid
          echo Please Enter A Valid Path
          read SOURCE
  fi
  done
  tar -czvf $BACKUP_FILE $SOURCE && echo "Backup Done" || echo "Backup Failed"
  ;;
   
  "2") echo You Selected Option 2
  echo Please Enter The File You Wish To Backup
  read SOURCE
   
  while [[ $VALID_PATH -eq 0 ]]
   
  do
   
  if [[ -f "$SOURCE" ]]; then
          VALID_PATH=1
          BACKUP_FILE="$BACKUP_DIR""$BACKUP_FILE"
  else
          echo This Path Is Invalid
          echo Please Enter A Valid Path
          read SOURCE
  fi
  done
  tar -czvf $BACKUP_FILE $SOURCE && echo "Backup Done" || "Backup Failed"
  ;;
   
  "3") echo You Selected Option 3
  echo Contents Of The Backup Directory
  ls $BACKUP_DIR
  echo Please Enter The Name Of The File You Wish To Restore
  read RESTORE_FILE
  RESTORE_FILE="$BACKUP_DIR""$RESTORE_FILE"
   
  while [[ $VALID_PATH -eq 0 ]]
   
  do
  if [[ -f $RESTORE_FILE ]]
  then
  VALID_PATH=1
  else
  echo This Path Is Invalid
  echo Contents Of The Backup Directory
  echo
  ls "$BACKUP_DIR"
  echo
  echo Please Enter The Name Of The File You Wish To Restore
  read RESTORE_FILE
  RESTORE_FILE="$BACKUP_DIR""$RESTORE_FILE"
  fi
  done
   
  echo
  echo The File $RESTORE_FILE Will Be Used To Perform A Restore
  echo
  tar -xzvf $RESTORE_FILE
  ;;
   
  "4") echo Goodbye
  exit 0;;
   
  esac
   
  if [ $OPTION -eq 1 -o $OPTION -eq 2 ]; then
  echo
  echo SUCCESS!
  echo
  echo The Following Files Were Backed Up To $BACKUP_FILE
  echo
  tar -tf $BACKUP_FILE
  elif [ $OPTION -eq 3 ]; then
  echo
  echo SUCCESS
  echo
  echo Your Files/Directories Were Restored
  fi

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding an extension to a group of filenames

Hi - I'm stuck. I have a group of text files created using the split command. My files have the names "projectaa", "projectab", "projectac", etc. What I want to do is add the extension ".txt" to each file. I think I've got part of a sed command together, but I'm stuck on my regex - I keep getting... (9 Replies)
Discussion started by: pepintheshort
9 Replies

2. UNIX for Dummies Questions & Answers

tar contains duplicate filenames

I have a problem where tar is somehow creating duplicate filenames when tarring a directory. Doing an ls on the directory does not show any duplicate filenames, yet when the directory is tarred, you can see that there are duplicates: bash-2.03# pwd /var/log/cricket bash-2.03# ls -1 | sort |... (2 Replies)
Discussion started by: dangral
2 Replies

3. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

4. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

5. Shell Programming and Scripting

Adding file to an existing tar

Hi Friends, I want to know the command to add a new file in a existing tar file. For Ex: I have a tar file file1.tar with the contents one.txt two.txt three.txt Now I need to add file four.txt to this existing tar file, how can I do it? Thanks in advance (4 Replies)
Discussion started by: mr_manii
4 Replies

6. Shell Programming and Scripting

tar cmd how many arguments into parameters of filenames

Hi I would like to use tar cmd in my script. I have a variable with filenames, e.g. 1000 records and I would like to paste its values into tar cmd. For this example I used three elements variable strings. strings="file1.txt file2.txt file3.txt" `tar cf file1.tar $strings` Whether... (1 Reply)
Discussion started by: presul
1 Replies

7. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

8. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

9. AIX

Tar - pre-checking before making the Tar file

Coming from this thread, just wondering if there is an option to check if the Tar of the files/directory will be without any file-errors without actually making the tar. Scenario: Let's say you have a directory of 20GB, but you don't have the space to make Tar file at the moment, and you want... (14 Replies)
Discussion started by: filosophizer
14 Replies
SMBTAR(1)                                                          User Commands                                                         SMBTAR(1)

NAME
smbtar - shell script for backing up SMB/CIFS shares directly to UNIX tape drives SYNOPSIS
smbtar [-r] [-i] [-a] [-v] {-s server} [-p password] [-x services] [-X] [-N filename] [-b blocksize] [-d directory] [-l loglevel] [-u user] [-t tape] {filenames} DESCRIPTION
This tool is part of the samba(7) suite. smbtar is a very small shell script on top of smbclient(1) which dumps SMB shares directly to tape. OPTIONS
-s server The SMB/CIFS server that the share resides upon. -x service The share name on the server to connect to. The default is "backup". -X Exclude mode. Exclude filenames... from tar create or restore. -d directory Change to initial directory before restoring / backing up files. -v Verbose mode. -p password The password to use to access a share. Default: none -u user The user id to connect as. Default: UNIX login name. -a Reset DOS archive bit mode to indicate file has been archived. -t tape Tape device. May be regular file or tape device. Default: $TAPE environmental variable; if not set, a file called tar.out . -b blocksize Blocking factor. Defaults to 20. See tar(1) for a fuller explanation. -N filename Backup only files newer than filename. Could be used (for example) on a log file to implement incremental backups. -i Incremental mode; tar files are only backed up if they have the archive bit set. The archive bit is reset after each file is read. -r Restore. Files are restored to the share from the tar file. -l log level Log (debug) level. Corresponds to the -d flag of smbclient(1). ENVIRONMENT VARIABLES
The $TAPE variable specifies the default tape device to write to. May be overridden with the -t option. BUGS
The smbtar script has different options from ordinary tar and from smbclient's tar command. CAVEATS
Sites that are more careful about security may not like the way the script handles PC passwords. Backup and restore work on entire shares; should work on file lists. smbtar works best with GNU tar and may not work well with other versions. DIAGNOSTICS
See the DIAGNOSTICS section for the smbclient(1) command. VERSION
This man page is correct for version 3 of the Samba suite. SEE ALSO
smbd(8), smbclient(1), smb.conf(5). AUTHOR
The original Samba software and related utilities were created by Andrew Tridgell. Samba is now developed by the Samba Team as an Open Source project similar to the way the Linux kernel is developed. Ricky Poulten wrote the tar extension and this man page. The smbtar script was heavily rewritten and improved by Martin Kraemer. Many thanks to everyone who suggested extensions, improvements, bug fixes, etc. The man page sources were converted to YODL format (another excellent piece of Open Source software, available at ftp://ftp.icce.rug.nl/pub/unix/) and updated for the Samba 2.0 release by Jeremy Allison. The conversion to DocBook for Samba 2.2 was done by Gerald Carter. The conversion to DocBook XML 4.2 for Samba 3.0 was done by Alexander Bokovoy. Samba 3.5 06/18/2010 SMBTAR(1)
All times are GMT -4. The time now is 08:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy