Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, Im', trying to automate the creation and archiving of backups. For that purpose, at the end of a week I want co copy the dayly backup files to a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2005
    Location
    Switzerland
    Posts
    24

    Creating a folder with the current date as name


    Hi,

    Im', trying to automate the creation and archiving of backups. For that purpose, at the end of a week I want co copy the dayly backup files to a new directory named according to the current date (within a script file). I tryed

    mkdir new
    mv new date +%y%m%d

    but the renaming does not work. Does anyone have an idea how to do that ?

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,864
    you need to encase the 'date' command in ` style quotes, so it gets executed not just used as a parameter, try:

    mkdir "`date`"

    Note which quotes have been used, the ones on the button on the top left of the keyboard, under or right next to the escape key...

    You can either do it directly like this, or use this syntax with the 'mv' command after you have created the directory with mkdir and filled it.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Jul 2005
    Location
    Switzerland
    Posts
    24
    Thank's. Now

    mkdir `date +%y%m%d`
    mv Home_C.*.dar `date +%y%m%d`/

    create the directory and copy the bakup file into it

    By the way, do you have any idea how to get DAR to create backup files with an "incremental" file name automaticaly (each day with a new name) ?
    Now I run DAR and then reanme the file from within a scrip file, but there should be a simpler way to do it, no ?

  4. #4
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    Code:
      mkdir `date +%y%m%d`
      mv    Home_C.*.dar   `date +%y%m%d`/
    Just don't try this at the stroke of midnight... :P


    I would like to suggest that you only "call" the 'date' command once:

    Code:
    DATE=`date +%y%m%d`
    Then, use the variable DATE after that as many times as you need it. This is especially important if you are using hours, minutes, seconds...


    Also, if this is going to be a "system" script - especially under root control - you should use the full path for 'date' (i.e., '/bin/date') and any/all other calls as well.

  5. #5
    Just Joined!
    Join Date
    Jul 2005
    Location
    Switzerland
    Posts
    24
    Right about calling date only once !

    By the way why should the use of complete path be needed ?

  6. #6
    Banned CodeRoot's Avatar
    Join Date
    Sep 2005
    Posts
    567
    If you don't use the full path - the file is searched for using the PATH variable list -- which would allow the possibility of another 'date' file (not the one you wanted) being found first.

Posting Permissions

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