LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Trying to backup files using a file list and tar (https://www.linuxquestions.org/questions/programming-9/trying-to-backup-files-using-a-file-list-and-tar-829786/)

BlackCrowe 09-01-2010 02:01 PM

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.

smoker 09-01-2010 02:16 PM

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

Sergei Steshenko 09-01-2010 02:35 PM

Quote:

Originally Posted by BlackCrowe (Post 4085176)
...
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" ?

grail 09-02-2010 01:47 AM

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

smoker 09-02-2010 01:27 PM

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

BlackCrowe 09-02-2010 02:30 PM

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.

grail 09-02-2010 07:00 PM

My bad :redface: in my defense it was 4am here :)

Eduardo Nunes 09-03-2010 03:11 PM

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

BlackCrowe 09-15-2010 10:06 AM

Trying to backup files using a file list and tar
 
Thanks Eduardo that worked.


All times are GMT -5. The time now is 03:25 AM.