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
ECHO(3) 								 1								   ECHO(3)

echo - Output one or more strings

SYNOPSIS
void echo (string $arg1, [string $...]) DESCRIPTION
Outputs all parameters. echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syn- tax only works with the short_open_tag configuration setting enabled. I have <?=$foo?> foo. PARAMETERS
o $arg1 - The parameter to output. o $... - RETURN VALUES
No value is returned. EXAMPLES
Example #1 echo examples <?php echo "Hello World"; echo "This spans multiple lines. The newlines will be output as well"; echo "This spans multiple lines. The newlines will be output as well."; echo "Escaping characters is done "Like this"."; // You can use variables inside of an echo statement $foo = "foobar"; $bar = "barbaz"; echo "foo is $foo"; // foo is foobar // You can also use arrays $baz = array("value" => "foo"); echo "this is {$baz['value']} !"; // this is foo ! // Using single quotes will print the variable name, not the value echo 'foo is $foo'; // foo is $foo // If you are not using any other characters, you can just echo variables echo $foo; // foobar echo $foo,$bar; // foobarbarbaz // Some people prefer passing multiple parameters to echo over concatenation. echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . " "; echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! END; // Because echo does not behave like a function, the following code is invalid. ($some_var) ? echo 'true' : echo 'false'; // However, the following examples will work: ($some_var) ? print 'true' : print 'false'; // print is also a construct, but // it behaves like a function, so // it may be used in this context. echo $some_var ? 'true': 'false'; // changing the statement around ?> NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. SEE ALSO
print(3), printf(3), flush(3), Heredoc syntax. PHP Documentation Group ECHO(3)
All times are GMT -4. The time now is 04:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy