Find the answer to your Linux question:
Results 1 to 4 of 4
I'm trying to make a backup script that will create a directory with the date and then copy the files to that new date directory and then create a tar ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2006
    Posts
    82

    backup script help


    I'm trying to make a backup script that will create a directory with the date and then copy the files to that new date directory and then create a tar file with the date. Here is what I'm after, but I don't know what code would be for date (I just put in %date% for example). Any help would be great. Thanks

    cd /backups/
    mkdir %date%
    cd /backups/%date%
    cp -r /home/www/* /backups/%date%
    tar -cvzf /backups/%date%.tar.gz /backups/%date%/

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,844
    You probably want to capture the output of the 'date' command into a variable, and use it repeatedly. The 'date' command reports the time and date including seconds, so its output changes frequently, so its not just a convenience to call it once, but a necessity.

    You can change the format of the time and date reported by 'date' with command line flags.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux Guru antidrugue's Avatar
    Join Date
    Oct 2005
    Location
    Montreal, Canada
    Posts
    3,211
    There is so many threads on that subject, I'm sure you can find something interesting in one of them.

    Like this one for example :
    http://www.linuxforums.org/forum/lin...t-newbies.html
    "To express yourself in freedom, you must die to everything of yesterday. From the 'old', you derive security; from the 'new', you gain the flow."

    -Bruce Lee

  4. #4
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Location
    Maryland, USA
    Posts
    510
    Unless there is a reason (like rapidly changing data files), I wouldn't copy everything and then tar it, I would just tar it in place.

    For example, today this would create file /backups/www090806.tar.gz which backs up all files in /home/www.
    Code:
    tar -cvzf /backups/www$(date +%m%d%y).tar.gz /home/www

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •