tar inside cron

hi,

i would like to backup some file everyweek

0 0 * * 0 tar -cvf abc.tar abc;gzip abc.zip

i would not replace the abc.zip,

thats mean the next week backup will become abc.zip1 ....abczip2........

how?

btw, is the any way beside '0 0 * * 0 tar -cvf abc.tar abc;gzip abc.zip' ?

thanx
bsherAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
bedotCommented:

0 0 * * 0 tar -cvf abc.tar abc;name=abc.zip;extent=`date +%W`; name=${name}$extent;gzip $name

that create each week a backup zipped with the extent is suffixed with the numero of the week in the year


format options of date:

.....
    U   Week number of the year (Sunday as the first day of the week) as a
        decimal number in the range 00 - 53

    W   Week number of the year (Monday as the first day of the week) as a
        decimal number in the range 00 - 53

    X   Current time, as defined by the locale

    Y   Year (including century), as decimal numbers

    Z   Timezone name, or no characters if no timezone exists

    a   Abbreviated weekday - Sun to Sat

    b   Abbreviated month name

    c   current date and time, as defined by the locale

    d   Day of month - 01 to 31
.....

(see man pages of date)
0
 
bsherAuthor Commented:
i  tried this way but failed

tar -cvf /home/abc/backup.tar
/home/abc/file/*.txt
/home/abc/file/data/*.txt;
name=backup.tar;extent='date+%W';
name=${name}$extent;
gzip /home/abc/$name

home/abc/file/word.txt
home/abc/file/time.txt
home/abc/file/data/mail.txt
home/abc/file/data/user.txt
/home/abc/backupdate+%W: No such file or directory

i would like to backup the *.txt from 2 different dir

once a week , eg:
1 nov 99 backup.tar.gzip.1

7 nov 99 backup.tar.gzip.2
             backup.tar.gzip.1

14 nov 99  backup.tar.gzip.3
                   backup.tar.gzip.2
                     backup.tar.gzip.1

thanx
bsh
0
 
j2Commented:
you are over complicating the problem

tar czvf abc.tgz`date +%V` abc

will create abc.tgzWEEKNUMBEROFYEAR

but tar czvf abc`date +%V`.tgz will prolly look cleaner.

will do the trick. note that the ` is a BACKTICK, it is NOT a ' or a ´
0
All Courses

From novice to tech pro — start learning today.