Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This might do better at StackExchange but I use Ubuntu as my file server.

So I'm trying to use tar and gzip to only backup the last 6 months of changes on my file server and it isn't working. It doesn't gzip anything, it puts the tar file in the same directory as the script(not what i want), and it changes the name of the file to part of the tar string.

Here is the script:

#!/bin/bash


tod=$(date +%F_%H%M%S)
echo "start"
echo $tod

echo "testing tar, only the last 6 months"
tar -cvf--newer-mtime=08-11-2013 /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar /homedepot/yellowsolo/xz/official/official /homedepot/yellowsolo/xz/home/home

echo "now zipping"
gzip /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar.gz

echo $tod
echo "done"
exit

Thanks in advance

share|improve this question
1  
You have the wrong syntax for your tar options. First, you need a space between "-cvf" and "--newer-mtime=08-11-2013", '-cvf --newer-mtime=08-11-2013' and second the date syntax is 20130811 , see stackoverflow.com/questions/10367037/… . As an alternate, and perhaps simpler backup, consider rsync ;) –  bodhi.zazen Feb 18 at 17:59
    
I rsync everything from another server to this one to archive it. –  troylatroy Feb 18 at 18:21
add comment

2 Answers 2

up vote 7 down vote accepted

Try:

#!/bin/bash
tod=$(date +%F_%H%M%S)
echo "Start"
echo $tod

echo "testing tar, only the last 6 months"
tar --newer-mtime=20130811 -cvzf /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar /homedepot/yellowsolo/xz/official/official /homedepot/yellowsolo/xz/home/home

echo "Done"
exit

I have cleaned up the errors in the tar command - you need to have f option before the filename, and filtered it through gzip (the z option).

share|improve this answer
    
+1 for pointing out use of tar filename just after -f option. –  souravc Feb 18 at 18:52
    
It works. Thanks! –  troylatroy Feb 18 at 18:56
add comment

At first you have tried to create a .tar file. Apart from the syntax error bodhi.zazen already pointed out your tar file name should come just after -f option. As Wilf aptly pointed out in his answer.

tar --newer-mtime=08-11-2013 -cvf /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar /homedepot/yellowsolo/xz/official/official /homedepot/yellowsolo/xz/home/home

Next there is another error. You are going to gzip /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar.gz but this file does not exist.

Rather you have a file /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar

You should use,

gzip /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar

It will create /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar.gz.

Note:

You can do it directly,

tar --newer-mtime=08-11-2013 -cvzf /homedepot/yellowsolo/xz/6months/xz$tod-last6months.tar.gz /homedepot/yellowsolo/xz/official/official /homedepot/yellowsolo/xz/home/home

-z switch zip tar simultaneously.

share|improve this answer
1  
There was something wrong - there was no space the -cvf. Also, @bodhi was right in that the date syntax was wrong. Good anyway +1 –  Wilf Feb 18 at 18:25
1  
yes you are correct. at the same time OP was trying to gzip a file that does not exist. is not it? –  souravc Feb 18 at 18:30
    
Yep :D @souravc –  Wilf Feb 18 at 18:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.