LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-01-2010, 02:01 PM   #1
BlackCrowe
Member
 
Registered: Aug 2010
Posts: 41

Rep: Reputation: 0
Trying to backup files using a file list and tar


I'm trying to backup quite a few directories and various files to a dated folder but not sure how to put it all together and make it work.

I want to avoid using something like backup_files="/home /var/spool/mail /etc /root /boot /opt"
because there's too many files.

I created a list of files I wanted backed up and that I could use with tar.
[root@hostname]# cat backup_list.txt|xargs tar cf backup_list.tar

I now have this backup_list.tar file but not sure how/where to place it in the script.

(Also while creating this backup_list.tar file there is an issue with having directory paths using the wildcard such as /var/log/audit/audit.log.*.gz)

What I have in the script is and I'm just trying it out with one directory right now but even this isn't working.
The dated directory is being created but the tar portion isn't working. It should tar the data from /opt/logs, giving the name of hostname .tar.gz and then move it to the dated folder in /mnt/dump/

mkdir /mnt/dump/hostname_`date +%Y%m%d`
tar -cvf /mnt/dump/hostname_`date +%Y%m%d` /hostname.tar.gz /opt/logs

The message I get when I run this is,

tar: Removing leading `/ from member names
tar: hostname.tar.gz: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

Thanks in advance for any help.
 
Old 09-01-2010, 02:16 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
What do you get if you run the commands from the command line ?
Does the directory get created ?
Is there a space in the tar command, causing the file name to be interpreted as a file to be tarred ?

Also, you need to specify that the tar should be zipped, by zipping it separately or using tar to do it. Don't expect the gz extension to magically zip the file. In fact that's your problem. Try it without the .gz

Last edited by smoker; 09-01-2010 at 02:22 PM.
 
Old 09-01-2010, 02:35 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by BlackCrowe View Post
...
mkdir /mnt/dump/hostname_`date +%Y%m%d`
tar -cvf /mnt/dump/hostname_`date +%Y%m%d` /hostname.tar.gz /opt/logs
...
Why do you have a space between "/mnt/dump/hostname_`date +%Y%m%d`" and "/hostname.tar.gz" ?
 
Old 09-02-2010, 01:47 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,564

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Quote:
tar -cvf /mnt/dump/hostname_`date +%Y%m%d` /hostname.tar.gz /opt/logs
How about the fact that the name of your tarred and gzipped file should be the first argument after your switches?
Try:
Code:
tar -czvf /hostname.tar.gz /mnt/dump/hostname_`date +%Y%m%d` /opt/logs
Or if only looking for the tar:
Code:
tar -cvf /hostname.tar /mnt/dump/hostname_`date +%Y%m%d` /opt/logs
 
Old 09-02-2010, 01:27 PM   #5
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 248Reputation: 248Reputation: 248
@grail
I think you missed the point. The filename is supposed to be /mnt/dump/hostname_`date +%Y%m%d` /hostname.tar.gz

He has given the full path to the file, but incorrectly.
 
Old 09-02-2010, 02:30 PM   #6
BlackCrowe
Member
 
Registered: Aug 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Trying to backup files using a file list and tar

I did get the script to work. Thanks all for helping me see the light.

Sergi- Yes there was a space between "/mnt/dump/hostname_`date +%Y%m%d`" and "/hostname.tar.gz" I removed the space and it worked.

smoker- Sorry -cvf should have been -czf that was a typo. I did run the commands from the command line and the dated directory was getting created.

grail- I didn't get to your suggestion. I had gotten it work work by then.

Now that it's figured out I have this other issue I mentioned earlier.

I was testing with just one directory but want to backup up several directories and files with a mix of ziped and unzipped files. I see that there is the -I include-file command but I'm not sure how to use it.

I created a list of files I wanted backed up and that I could use with tar.
[root@hostname]# cat backup_list.txt|xargs tar cf backup_list.tar

I now have this backup_list.tar file but not sure how/where to place it in the script.

Also while creating this backup_list.tar file there is an issue with having directory paths using the wildcard such as /var/log/audit/audit.log.*.gz.
 
Old 09-02-2010, 07:00 PM   #7
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,564

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
My bad in my defense it was 4am here
 
Old 09-03-2010, 03:11 PM   #8
Eduardo Nunes
LQ Newbie
 
Registered: Aug 2010
Location: /root/SouthAmerica/Brazil/SaoPaulo/SP
Distribution: Slackware
Posts: 24

Rep: Reputation: 2
Post

Hi BlackCrowe!

I do believe you wanna have something like:

Code:
mkdir /mnt/dump/hostname_`date +%Y%m%d`
tar -czf /mnt/dump/hostname_`date +%Y%m%d`/hostname.tar.gz `cat backup_list.txt | xargs`
Hope that solves the question for you

Regards,

Eduardo Nunes
 
1 members found this post helpful.
Old 09-15-2010, 10:06 AM   #9
BlackCrowe
Member
 
Registered: Aug 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Trying to backup files using a file list and tar

Thanks Eduardo that worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to tar a list of files lakshan Linux - General 2 02-11-2010 11:41 PM
Backup files but not using tar tqz Linux - Newbie 6 08-14-2009 11:02 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
untar a list of tar files? Rotwang Linux - General 6 10-10-2006 01:34 PM
list files in a tar.gz file linuxtesting2 Linux - Newbie 4 09-23-2004 02:49 AM


All times are GMT -5. The time now is 11:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration