Find the answer to your Linux question:
Results 1 to 5 of 5
Yet more backup questions. I use Code: sudo tar -cvf /media/disk/filedate.tar /etc sudo tar -cvf /media/disk/filedate.tar /home/joe What I want to do is write a short script(mybackup) that will automate ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    39

    how to write a backup script?

    Yet more backup questions. I use

    Code:
    sudo tar -cvf /media/disk/filedate.tar  /etc
    sudo tar -cvf /media/disk/filedate.tar /home/joe
    What I want to do is write a short script(mybackup) that will automate that for me, so when I type mybackup it executes the commands AND replaces the "filedate.tar" with "the date of that day".tar.

    Possibly using some variation of the "date" command. I tried
    Code:
     date %m%d%y
    and that gives me the output I want. How do I sub that for filedate.tar in the script?

    Thanks in advance

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Well here are two things to start you off.
    • I see you are using sudo. If the script needs root access, run it as root. You should use sudo in scripts. Maybe a cron job under root could do it for you
    • When using the date command, you're best to use the YYYYMMDD format, i.e. high-to-low. That way you have an inherent file sorting and the output directory won't seem as garbled
    Try this
    Code:
    tar -cvf /media/disk/$(date +%Y%m%d).tar /home/joe
    If you intend using the date a few times, set it into a variable and then use the variable in each command. That way if the day changes during the script you won't get inconsistent results
    Code:
    BACKUPDATE=$(date +%Y%m%d)
    tar -cvf /media/disk/$BACKUPDATE.tar /home/joe
    Also, you've used the same archive name for both backups. Don't forget to put something into the name to distinguish them, or at least don't use the create switch the second time.

  3. #3
    Linux Guru jmadero's Avatar
    Join Date
    Jul 2007
    Location
    California
    Posts
    1,958
    no need to do a script

    sudo apt-get install sbackup

    then go to system-> admin -> sbackup configuration

    you can set it for however frequently and what folders. It'll auto make a compressed folder with everything in it
    Bodhi 1.3 & Bodhi 1.4 using E17
    Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17

    "The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"

  4. #4
    Just Joined!
    Join Date
    Apr 2009
    Posts
    39
    jmadero, thanks for your reply

    bigtomrodney, thank you for your practical and clear reply. Sounds like you have the answer and I will try that very soon.
    BACKUPDATE=$(date +%Y%m%d)
    tar -cvf /media/disk/$BACKUPDATE.tar /home/joe
    Thanks again

  5. #5
    Just Joined!
    Join Date
    Apr 2009
    Posts
    39
    Thank You for all your help. Problem is solved

Posting Permissions

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