Results 1 to 8 of 8

Thread: Backup script questions

  1. #1
    Join Date
    Jul 2011
    Location
    Off the grid
    Beans
    119
    Distro
    Ubuntu 12.04 Precise Pangolin

    Backup script questions

    I have created this script from ubuntu wiki pages:
    #!/bin/bash
    # Backup Script
    #
    #What to backup.
    backup_files="/home/mrc/"
    #Where to place backup.
    dest="/home/mrc/backup/"
    #Create archive filename.
    day=$(date +%d%m%Y-%R)
    hostname=$(hostname -s)
    archive_file="$hostname-$day.tgz"
    #Print start status message.
    echo "Backing up $backup_files to $dest/$archive_file"
    date
    echo
    #Backup the files using tar.
    tar czf $dest/$archive_file $backup_files --exclude 'backup/*' --exclude 'backup'
    #Print end status message.
    echo
    echo "Backup finished"
    date
    #Long listing of files in $dest to check file sizes.
    ls -lh $dest
    My question is however, how to I get rid of this line when I run the script:
    tar: Removing leading `/' from member names
    The script is successfull. BUT I'm getting tired of that line...
    Last edited by MadsRC; March 1st, 2012 at 02:46 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,726
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Backup script questions

    I know this doesn't really answer your question, but I'd give up on the method you're trying to develop and jump to rsync. You can exclude directories with this method. rsync has been used and developed for years and is made with one purpose in mind -- backups.

  3. #3
    Join Date
    Jan 2012
    Beans
    342

    Re: Backup script questions

    Quote Originally Posted by MadsRC View Post
    I have created this script from ubuntu wiki pages [...] My question is however, how to I get rid of this line when I run the script:
    tar: Removing leading `/' from member names
    The script is successfull. BUT I'm getting tired of that line...
    skip long digression about the use of '-P' and the removing of the leading slash .. yadda-yadda.

    Ugly little script, '-C' should fix it ... here's the 'braceified' version

    Code:
    #!/bin/bash
    
    BACKUP_FILES="${HOME}/prj/"
    DEST="${HOME}/backup/"
    DAY=$(date +%A)
    HOSTNAME=$(hostname -s)
    ARCHIVE_FILE="${HOSTNAME}-${DAY}.tar.gz"
    
    echo "Backing up $BACKUP_FILES to ${DEST}/${ARCHIVE_FILE}"
    tar czf ${DEST}/${ARCHIVE_FILE} -C ${BACKUP_FILES}
    echo "Backup finished"
    HTH ... khay

  4. #4
    Join Date
    Jul 2011
    Location
    Off the grid
    Beans
    119
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Backup script questions

    Thank you Khay.

    I'm learning Bash, I know it could be prettier

    However, executing that script yields:
    Backing up to /home/mrc/backup//mrc-Thursday.tar.gz
    tar: option requires an argument -- C
    Try `tar --help' or `tar --usage' for more information.
    Backup finished

  5. #5
    Join Date
    Jan 2012
    Beans
    342

    Re: Backup script questions

    Quote Originally Posted by MadsRC View Post
    Thank you Khay.
    I'd say "your welcome" had I got it right first time ... so, now having tested it

    Code:
    #!/bin/bash
    
    BUP_FILES_DIR="prj"
    DEST="${HOME}/backup"
    ARCHIVE_FILE="$(hostname -s)-$(date +%F).tar.gz"
    
    echo "Backing up ${HOME}/${BUP_FILES_DIR} to ${DEST}/${ARCHIVE_FILE}"
    tar -C ${HOME} -czf ${DEST}/${ARCHIVE_FILE} ${BUP_FILES_DIR}
    
    if [[ $? == 0 ]]; then
        echo ""
        echo "Backup finished"
    else
        echo ""
        echo "There was a problem completing the backup"
    fi
    Note I've changed "date +%A" to "date +%F" ... which seems a little more informative ... you can obviously change it back if you so wish.

    best ... khay
    Last edited by Khayyam; March 1st, 2012 at 05:02 PM.

  6. #6
    Join Date
    Jul 2011
    Location
    Off the grid
    Beans
    119
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Backup script questions

    Thank you

    Found a problem with it though. tar gives an I/O error when untar'ing the backup file created. Both on my server and if I download it to my local pc... Untar'ing it with the gui works though...

    Solved it by chaning the time format from ":" to "_"

    Used your code to modify my existing, will post it when it's done

  7. #7
    Join Date
    Jan 2012
    Beans
    342

    Re: Backup script questions

    Quote Originally Posted by MadsRC View Post
    Thank you
    Your welcome ...

    Quote Originally Posted by MadsRC View Post
    Found a problem with it though. tar gives an I/O error when untar'ing the backup file created. Both on my server and if I download it to my local pc [...] solved it by chaning the time format from ":" to "_".
    The date format 'date +%F' is "-" (dash) seperated, there should be no problem with dashes.

    Quote Originally Posted by MadsRC View Post
    Used your code to modify my existing, will post it when it's done.
    OK ... best ... khay

  8. #8
    Join Date
    Jul 2011
    Location
    Off the grid
    Beans
    119
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Backup script questions

    Ah sorry, It was actually my own code that messed it all up.

    Think I got it now Wouldn't learn anything if I didn't break stuff

Bookmarks

Posting Permissions

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