Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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
    Nottingham, England
    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

  3. #3
    Linux Guru antidrugue's Avatar
    Join Date
    Oct 2005
    Montreal, Canada
    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 :
    "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. $spacer_open
  5. #4
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Maryland, USA
    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.
    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