Tar file with newly created file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Tar file with newly created file
# 1  
Old 08-14-2018
Tar file with newly created file

Hello guys
thanks for this helpful forum.

I'm new to scripting and doing a little script that dump a sql database with some extra files from a VM of the company I'm in, and create a tar archive to be saved on our serve.

How can I have the tarball to be created with the files generated in the same script?
I keep getting: "cannot extract file, archive empty"

I've tried a wait 10 but that doesn't help.

Code:
#!/bin/bash
#
#VARIABLES
#working directory
wd=/opt/fs_db_backup/
if [ ! -d $wd ] ; then
   mkdir $wd
fi
runDate=`date +%d_%m_%y-%H%M%S`
vers=$(/home/leo/bin/leostatus | grep vers | awk '{print $5}' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g")
#DUMPING THE DATABASE
/usr/local/pgsql/bin/pg_dump -U leo -f $wd/sql
#CREATES FILE NEEDED FOR RESTORATION
touch $wd/version
touch $wd/md5
#populate and change permissions
echo -n $vers >> $wd/version
#respect the order 
cd $wd
md5sum sql >> md5
md5sum version >> md5
chmod -R 640 $wd
#getting everything ready for archive
#mv /opt/fs_db_backup/* /opt/fs_db_backup/tar
#create tar file for backup with absolue path
tar -czvf leo_db_backup-"$runDate".tgz /opt/fs_db_backup/*
#chmod -R 660 leo_db_backup-*
#rsync to server
#rsync -ravptx $tarpath/leo* root@server01/
#weekly retention?

Thank you!
# 2  
Old 08-14-2018
Things that I see -

1. execute cd or do what it takes to make the process current working directory NOT to be the directory you are tarring up. Just a good idea.

2. have tar write the archive to /tmp or some other directory, not $wd, then mv the archive file into $wd if that is its final resting place. What happens in your code now is tar creates the file because of the c option, then tries to backup the file it has open. My opinion anyway.
# 3  
Old 08-14-2018
Good shout. Ended up mv files into subfolders and tar accordingly

what a brainfart!

this can be closed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

No iscsi available in newly created AIX wpar

AIX 7.1 New to WPAR, hopefully just missing something simple here. Creating the WPAR like this..... (The box where the WPAR is hosted does have an iscsi protocol device) mkwpar -h wpar08 -l -n wpar08 -N interface=en0 address=xxx.xx.xx.xxx netmask=255.255.255.0 -D devname=/dev/iscsi0 -D... (0 Replies)
Discussion started by: TomR
0 Replies

2. Hardware

Formatting a newly created lun

Hi , I have created one new lun in my SAN storage and make it visible to my HP servers , but the fdisk -l output is somehow confusing. Do not know what to do next ---------- fdisk -l /dev/sdo1 Disk /dev/sdo1 (Sun disk label): 64 heads, 32 sectors, 10238 cylinders Units =... (7 Replies)
Discussion started by: mishra.sankar
7 Replies

3. Shell Programming and Scripting

Copy an array to a newly created directory

hello everyone, I am new to perl script and trying to develop a script as follows. I am trying to Create an array for storing all file names. I am trying to copy $libs into "scratch". however i am unable to do so. Please suggest.. #!/usr/bin/perl use File::Copy; #use... (5 Replies)
Discussion started by: Rashid Khan
5 Replies

4. Solaris

Can't see Newly created LUN by SAN admin

hello, i am an oracle DBA and trying to scan a newly created LUN of 200 GB on fiber channel by SAN admin.we have solaris 10 and SANtoolkit is installed.i tried following to get the new LUN at my machine. go /opt/Netapp/Santoolkit/bin and then ./sanlun lun show but i see only the existing... (12 Replies)
Discussion started by: janakors
12 Replies

5. UNIX for Advanced & Expert Users

default size of a newly created folder

Hi all, In linux how to create a directory with specified size, so that it can be used only up to the mentioned size. Actually my question is, whether we can do directory quota in linux. mounting the directory in a partiton will do that, but do we have any other option... (1 Reply)
Discussion started by: anishkumarv
1 Replies

6. Shell Programming and Scripting

sftp - get newly created files on incremental basis

Hi, We have a sftp server which creates files daily and keeps 6 months of files on the server. We are creating a daily job to get the files and load into database. My problem is "how to get ONLY those files which got created after my last get". Let me provide some more details to it. Below... (15 Replies)
Discussion started by: ravi.videla
15 Replies

7. Shell Programming and Scripting

How to find the newly created directory

Hi, I need to create new directory by increasing the number by 1 of extracted lastly created directory. e.g. Log\out_log_1\ Log\out_log_2\ Log\out_log_3\ become Log\out_log_1\ Log\out_log_2\ Log\out_log_3\ Log\out_log_4\ Can anyone help how to do it in c-shell... (3 Replies)
Discussion started by: Andre_2008
3 Replies

8. UNIX for Dummies Questions & Answers

Help with command to find all newly created files in a given time period

Hi all! Can someone please help me create a command to accomplish the following task. I have a parent directory called ex. /var/www/parent and it has a bunch of sub-directories called /var/www/parent/1, var/www/parent/1/xyz/ and etc. What I would like to do is to count the number of files... (2 Replies)
Discussion started by: bbzor
2 Replies

9. Shell Programming and Scripting

How to keep appending a newly created file based on some keywords

Hi Friends, I have to create a new log file everyday and append it with content based on some keywords found in another log file. Here is what I have tried so far... grep Error /parentfolder/someLogFile.log >> /parentfolder /Archive/"testlogfile_error_`date '+%d%m%y'`.txt" grep error... (6 Replies)
Discussion started by: supreet
6 Replies

10. UNIX for Advanced & Expert Users

How to FTP all newly created but the current open file?

An application running on HP-UX constantly generates new text log files ( I think using logpipe ). Any new file created requires to be ftp'ed to an offline server, however I want to make sure that the current file being written should not be transferred. For examples consider the following files... (3 Replies)
Discussion started by: indianya
3 Replies
Login or Register to Ask a Question