Help with adding to tar filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with adding to tar filenames
# 1  
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

# 2  
Old 12-16-2009
Not sure how often you run it but you could just add your wanted filename and also add seconds to the date so the names on the same day should be different for sure.
# 3  
Old 12-16-2009
its run whenever changes are made to the files by the user. the program allows to pick files from within several directories so there is no set filename to use, it all depends on which files are backed up. If i cant find a way to make it specific to the file then ill resort to the seconds.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
Login or Register to Ask a Question