Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 36

Thread: Easy Way To Backup Your System!! (Bash Script)

  1. #11
    Join Date
    Dec 2007
    Beans
    38

    Re: Easy Way To Backup Your System!! (Bash Script)

    Thanks for the backup script.

    In looking through the resulting backup file (backup.tgz) on my computer from the original script, I noted that about 800M of the 3.1G backup.tgz file is backup.tgz. This is in spite of the instructions in the script to exclude it.

    I also happened to be watching while the script was running (only occasionally, I have to admit) and saw a long pause when backup.tgz was shown as being added to the file. My thoughts were that it had to run through it anyway but would not add it, but that was apparently incorrect.

    The script crashes when run from the bin directory.

  2. #12
    Join Date
    Sep 2007
    Location
    Oklahoma, USA
    Beans
    2,356
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Easy Way To Backup Your System!! (Bash Script)

    Quote Originally Posted by 1915flyer View Post
    In looking through the resulting backup file (backup.tgz) on my computer from the original script, I noted that about 800M of the 3.1G backup.tgz file is backup.tgz. This is in spite of the instructions in the script to exclude it.
    While I've not tried running the script yet, I did note that the --exclude option for backup.tgz had "/" in front of it. This makes it an absolute path name, so it excludes a file named backup.tgz located in the root directory "/" but the actual backup file isn't there. It's in the home directory and thus isn't excluded.

    I think there are several options for fixing this. Simplest is to remove the "/" from that --exclude option so that any file named "backup.tgz" is excluded. Next is to add "$HOME" in front of the "/" to change the location to the user's home directory. Another would be to change the location to put the actual file into the "/" directory but this would require running the script with sudo since only root has write permission there.

    I did something similar when tweaking my configuration files, to save just the /etc directory so that I could easily roll back in case I messed things up (which I did several times). Here's my version:

    Code:
    #!/bin/bash
    #
    # backs up configuration files...
    
    NOW=`date +%Y%m%d%H%M`
    sudo tar cvpzf /home/jim/bak-$NOW.tgz /etc >/home/jim/list.txt
    exit 0
    Using the "NOW" temporary variable prevents overwriting older copies, and redirecting the output to "list.txt" creates a list of all that's backed up. Including "sudo" in the script makes it ask for the password when run.

    Backing up is a good idea, even though you may never want to restore a year-old system exactly. If you've installed extra packages such as VirtualBox, or tweaked firewall settings, you definitely need to save at least /etc in addition to your home directory if you expect to get back all of your customizations...
    --
    Jim Kyle in Oklahoma, USA
    Linux Counter #259718
    Howto mark thread: https://wiki.ubuntu.com/UnansweredPo.../SolvedThreads

  3. #13
    Join Date
    Mar 2010
    Beans
    40

    Arrow Re: Easy Way To Backup Your System!! (Bash Script)

    Okay,
    First off- thanks very much for all the comments and constructive criticisms. My self-esteem just jumped up a fair little bit =)
    And, as pointed out, the commands used in the script I learned from the following post-
    http://ubuntuforums.org/showthread.php?t=35087
    by the ubuntu forums user Heliode and, as pointed out, credit is due- im sorry for forgetting that part Heliode.
    I can assure you all that the script is entirely my own creation, but I learned how to backup/restore my system using Heliode's tutorial.
    So, credit to him/her and credit to you (mikewhatever) for pointing it out to me, athough I do feel that saying "this work is not original" is a bit strong as the script IS original, but the commands were learned from somewhere else. I wrote the script & tutorial myself.
    There's always something missing, eh?
    Okay,
    I'm in the process of writing v.1 of the restore script(which I will put in here asap), whilst ALSO addressing the issue raised about excess size of the backup.tgz file- I will do something about it.
    As far as the better, more efficient ways of backing up- yes, I would suggest you learn to use them, but if you are new and, as I stated initially, 'frightened' by this new, amazing being called ubuntu, then I would recommend you start by using this until you find your feet.
    NOTE: This is also intended as an introduction to automating processes and adding things to the PATH environment variable.
    As for the catch-22 of using this method, reinstalling & upgrading ubuntu, then restoring- one can use V.2 of my/your own version of the script to selectively exclude folders/files to ONLY backup your personal files, emails, etc...
    PLEASE LET ME KNOW IF I'M WRONG IN THINKING THIS, BY THE WAY!!

    Finally, I'm thinking of adding in a selection ability to pick whether you just want to do a standard backup, personal files backup, system files backup, etc...
    Do you all think this would be good?
    Input is greatly appreciated!!

    Once again, all input is appreciated. Ideas or creative criticism, I will take it ALL on board.
    Hope to continue helping you, check back later for my restore script(I will have it online within 24 hours- got dinner out tonight)

    !!! VIVA LA LINUX !!!

    lonewaster
    Last edited by lonewaster; March 6th, 2010 at 07:13 PM.

  4. #14
    Join Date
    Aug 2006
    Beans
    12,974
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Easy Way To Backup Your System!! (Bash Script)

    Quote Originally Posted by lonewaster View Post
    ...
    So, credit to him/her and credit to you (mikewhatever) for pointing it out to me, athough I do feel that saying "this work is not original" is a bit strong as the script IS original, but the commands were learned from somewhere else. I wrote the script & tutorial myself.
    ...
    Fare enough, I'll edit my previous post to 'inspired by'.

  5. #15
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Exclamation Dangerous

    This backup script is badly made, will not always backup files as expected and creates major security risks. Keep in mind, backup scripts are serious ****, making the slightest mistake could loose someone their files, which could land you in serious legal trouble. You should learn more about programming before you publish things like this.

    Sorry, I don't mean to be rude, but this could cause serious damage.

  6. #16
    Join Date
    Mar 2010
    Beans
    40

    Arrow Re: Dangerous

    Quote Originally Posted by Penguin Guy View Post
    This backup script is badly made, will not always backup files as expected and creates major security risks. Keep in mind, backup scripts are serious ****, making the slightest mistake could loose someone their files, which could land you in serious legal trouble. You should learn more about programming before you publish things like this.

    Sorry, I don't mean to be rude, but this could cause serious damage.
    Please explain so I can fix the issues!
    I mean...I set the backup script so that it would set the file's group and change the file permissions...so is it just a risk by having a copy of certain 'files', you mean?
    The way I see it, anyone worrying about their security would probably have better knowledge than the need to use this script anyway...I mean, I've said that it's aimed at first-timers as a kind-of tutorial and birth into the linux world or works..
    But please, let me know and I will fix / appropriately warn people

    mikewhatever: thanksmuch

    okay, well...here it is. As promised.
    the restore script !!
    Once again, credit to Heliode for his/her tutorial that taught me how to do this. And credit to me for writing the 'tutorial' and script

    REMEMBER: ALWAYS RUN YOUR NEW backup AND restore SCRIPT AS ROOT!
    NOTE: TO GET ROOT, I ALWAYS USE THE COMMAND-
    Code:
    sudo -i
    ALTHOUGH THERE ARE MOST LIKELY BETTER WAYS, WHICH I INVITE OTHERS TO POST HERE FOR THE REST OF US

    Here's the V.1.2 of the restore script (yes, I said V1.2 ! I decided to fix up the original a little bit before uploading it =)

    Code:
    #!/bin/bash
    # Print Pre-text Containing Script Version Info & Creator Info (please leave current credits intact and add a separate line if you modify the script & pass it on)
    clear
    echo "Restore Script"
    echo ""
    echo "V.1.2"
    echo ""
    echo "Created by Lonewaster@gmail.com"
    echo "VIVA LA LINUX!!!"
    echo ""
    read -p "Please Press ENTER To Continue..." waitForEnter
    # Alert The User & Wait 3 Clicks
    echo "RESTORE Initiating..."
    echo ""
    sleep 3
    # Ask the user for their ubuntu username so that the script can fetch the batch file from their home directory (needed as script is run as root)
    read -p "What username are you currently logged into? (must be IDENTICAL to username you are currently using!!): " restoreUser
    # Restore the system using the backup.tgz file located in the users home directory, which is selected using the $restoreUser variable we just set from the user input
    tar xvpfz /home/$restoreUser/backup.tgz -C /
    # Upon Completion, Alert The User
    echo ""
    echo "RESTORE Complete!"
    echo ""
    echo "Please REBOOT Your Computer To Complete The Restore."
    echo ""
    echo "After A Few Days, I Recommend You Run Another Backup, To Keep It Fresh!"
    echo ""
    # Alert The User, Wait 3 Clicks & Terminate The Script
    echo "TERMINATING..."
    echo ""
    sleep 3
    # End Of restore Script
    All the commands used in this script are pretty much the same as in our backup script from before, except the tar command, which has been edited to UNLOAD files from, instead of PACKING them into, the backup.tgz file (so to speak).

    Also, I upgraded the backup script a little to allow for some user choice in what happens.
    Here she is, in all her glory (and insecurities and what not )-
    Code:
    #!/bin/bash
    # Print Pre-text Containing Script Version Info & Creator Info (please leave current credits intact and add a separate line if you modify the script & pass it on)
    clear
    echo "Backup Script"
    echo ""
    echo "V.2.3"
    echo ""
    echo "Created by Lonewaster@gmail.com"
    echo "VIVA LA LINUX!!!"
    echo ""
    read -p "Please Press ENTER To Continue..." waitForEnter
    # Alert The User & Wait 3 Clicks
    echo "BACKUP Initiating..."
    echo ""
    sleep 3
    # Ask The User For Their Current Username (For Backup File Placement & Permissions)
    read -p "What username are you currently logged into? (must be IDENTICAL to username you are currently using!!): " backupUser
    echo "This version allows you to select WHAT kind of backup you wish to do."
    echo "Just type the number corresponding to the type you want, and hit enter."
    echo "[1] Standard backup (full system, standard exclusions. this will restore you computer to exactly as it is now)"
    echo "[2] Standard backup with optional exclusions (full system, you choose what to exclude from the backup)"
    echo "[3] Personal backup (ONLY backup personal files & folders, excludes system files. this will ONLY restore your personal files & folders)"
    echo ""
    read -p "So, What backup type would you like? (1 / 2 / 3): " backupType
    if [ $backupType = 1 ] 
        then
        # if the user chose to just do a standard full system backup
        # Tell him/her what the standard exclusions are...
        echo "Standard directory exclusions are-"
        echo "--exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys --exclude=/media"
        echo "If you want to add/remove any directories from this list, then use backup type [2]"
        strExclusions="--exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys --exclude=/media"
        # Then store the standard folder exclusions in our strExclusions variable
        strBackupFolder="/"
        # And Set The folder we want to backup as the base directory (root)
    elif [ $backupType = 2 ] 
        then
        # if the user chose to pick their own exclusions...
        # Ask the user for a list of folders to exclude from the backup.tgz
        echo "Enter any directories you want to exclude from the backup.tgz"
        echo "Syntax: --exclude=/folder"
        read -p "Please enter them now, each separated with a space: " strExclusions
        # And store them in strExclusions
        strBackupFolder="/"
        # And Set The folder we want to backup as the base directory (root)
    elif [ $backupType = 3 ] 
        then
        # if the user chose to just backup their personal files...
        # Tell him/her what folders will be excluded...
        echo "This backup type will ONLY backup the selected username's /home/ folder. This contains your Documents, Desktop, Video, Music, Pictures, Etc.. Folders"
        echo "If you would rather choose your own folders to exclude from the backup, then use backup type [2]"
        echo "If you would rather just backup the entire system, then use backup type [1]"
        strExclusions=""
        # Set no folder exclusions because we are only telling it to backup ONE folder (/home)
        strBackupFolder="/home/$backupUser"
    else
        # if a valid backup type wasn't entered then alert the user
        echo "Incorrect backup type selection (1 / 2 / 3)..."
        echo "Please try again!.."
        echo ""
        echo "TERMINATING..."
        echo ""
        sleep 3
        exit
        # and terminate the backup script
    fi
    # And if everything went okay, then backup the system, excluding all the folders the user chose (which are saved in $strExclusions)
    # We use the $strBackupFolder so that we can change the directory that is to be backed up, without having to use this command more than once(for the new type [3] backup!!)
    tar cvpzf ../../home/$backupUser/backup.tgz $strExclusions $strBackupFolder
    # Backup Entire System To the Specified User's homedir/backup.tgz (../../ included so script can be put in subdirectory)
    # Upon Completion Of Backup, Alert The User
    echo ""
    echo "BACKUP Complete!"
    echo ""
    # Then Set backup.tgz File Privilidges So That The Specified USER Can Read, Write & Execute
    echo "Setting Backup File Privilidges..."
    echo ""
    # Set The File's Group As the Specified $backupUser
    chgrp $backupUser ../../backup.tgz
    # Set Read, Write & Execute Privilidges For The Owner (root)
    chmod u+rwx ../../backup.tgz
    # Set Read, Write & Execute Privilidges For The Specified Group ($backupUser)
    chmod g+rwx ../../backup.tgz
    # Alert The User, Wait 3 Clicks & Terminate The Script
    echo "TERMINATING..."
    echo ""
    sleep 3
    # End Of backup Script
    If you want to know whats happening on a line-to-line basis, then just look at my comments (anything on a line after a # symbol).
    There isn't much of a difference....just the user choice part.
    This used a simple if/elseif/else statement, which are built like the following.
    Code:
    if [ this happens ]
    then
    do this code here
    elif [ this happens ]
    then
    so this instead of the bit above
    else
    do this when none of the above criteria are met
    fi
    What happens is first the code checks the first if [] statement to see IF its true, then IF it IS then it does the code after that bit.
    elif means else if. so otherwise IF[] such-and-such is true, then do that little bit of code.
    And we use an else statement for what happens if none of the other if/elif statement criteria are met.
    REMEMBER: GOOGLE IS YOUR FRIEND FOR ANY NEEDS, SO IF YOU STILL WANT TO LEARN MORE THEN GOOGLE IT AND CHECK THE REST OF THE FORUM!!!

    and, thx to penguin guy for pointing out potential security issues! so here's a warning for those who don't know better-
    WARNING: USING THIS BACKUP SCRIPT MAY CAUSE SECURITY ISSUES IN ITS CURRENT STATE, AND SO YOU ARE RECOMMENDED TO USE A SAFER SYSTEM IF YOU HAVE SOMETHING YOU WANT TO KEEP COMPLETELY SECURE, BUT FOR THOSE F YOU JUST STARTING OUT, UNLESS YOU HAVE LIKE NATIONAL SECRETS ON YOUR CMPUTER, THEN YOU SHOULD BE PRETTY SAFE!
    I PROMISE TO WORK ON SECURING THIS SYSTEM!!
    IF YOU WISH TO USE THIS SCRIPT & BE AS SECURE AS POSSIBLE THEN USE BACKUP TYPE [2] AND SPECIFY WHICH FOLDERS TO EXCLUDE FROM THE BACKUP, AND PREVENT ANY SECURITY ISSUES!!


    LEGAL NOTICE: I ACCEPT NO RESPONSIBILITY WHATSOEVER FOR ANY SECURITY RISKS RAISED BY THIS AND ANY OF MY SCRIPTS. YOU USE THEM AT YOUR OWN RISK.
    THAT SAID, I GUARANTEE ANYNE USING MY SCRIPT THAT I WILL HELP WHEREVER POSSIBLE TO MAKE IT BETTER AND SAFER AND TO REPAIR ANY DAMAGE THAT MAY RESULT FROM THE USE OF (ALTHOUGH IF USED CORRECTLY THEN THERE SHOULDN'T REALLY BE MUCH OF A PROBLEM).


    I'm not a big shell coder. I can when I need to, but I don't claim to be professional.
    I'm just a programmer in my spare time. If you have a better way to do things then i suggest you use it, as there is ALWAYS a better way to do something when it comes to programs.
    There is ALWAYS a security risk, and with every fix there opens another backdoor.
    This said I understand what it is like for people to change from windows to linux. (my mum and dad and sister were converted by me =D ) and this and possibly other stuff I make/post will be aimed at that sort of group.
    So long as you don't use this to backup anything you need to keep REALLY secure, or if you just create the backup and copy it to a CD/CDV then remove the file from your computer then I can see no real harm.
    BUT as I said- There is always a way into a system. And there is always someone who will be able to find their way in if they really want to.

    Anyway...Its 1:18AM here in bonny Scotland, so I shall return tomorrow probably.
    But for now, I sleeps

    !!! VIVA LA LINUX !!!

    lonewaster
    Last edited by lonewaster; March 7th, 2010 at 02:29 AM. Reason: addition of legal stuff and a little bit xtra

  7. #17
    Join Date
    Mar 2010
    Beans
    40

    Exclamation Re: Easy Way To Backup Your System!! (Bash Script)

    To any new users wondering about how hard it is to get into making your OWN scripts in ubuntu, let me tell you this-
    this is the first bash script I have ever put more than one line into.
    I didn't know how to backup my system manually until I read Heliode's tutorial thread.
    That's how easy it is!
    Just google for " ubuntu bash script tutorial " ( without the quotes ) and look for a beginners tutorial.
    My advice would be to get a book (such as a For Dummies book or whatever) and use that as a REFERENCE for when you are actually programming.
    I use a reference for all my programming languages. [HTML/CSS/JAVASCRIPT/PHP/PERL/C++/BYOND] and it makes a hell of a difference to my stress levels
    Just persevere, and you can do ANYTHING !!!

    !!! VIVA LA LINUX !!!

    lonewaster

  8. #18
    Join Date
    Mar 2009
    Beans
    927
    Distro
    Ubuntu 12.04 Precise Pangolin

    Exclamation Re: Dangerous

    Quote Originally Posted by lonewaster View Post
    Please explain so I can fix the issues!
    I mean...I set the backup script so that it would set the file's group and change the file permissions...so is it just a risk by having a copy of certain 'files', you mean?
    The way I see it, anyone worrying about their security would probably have better knowledge than the need to use this script anyway...I mean, I've said that it's aimed at first-timers as a kind-of tutorial and birth into the linux world or works..
    But please, let me know and I will fix / appropriately warn people
    Trust me, I have written my own backup script and there is a lot of stuff that can go wrong. Programs never work exactly as you expect. You really don't know what you're doing, at least put a warning on the front page:
    Warning: I cannot guarantee that this script will function as expected.
    This script comes with no warranty, not even the implied warranty of fitness for a particular purpose.

  9. #19
    Join Date
    Feb 2010
    Location
    Land of Confusion
    Beans
    8,359
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Easy Way To Backup Your System!! (Bash Script)

    Shouldn't have to put a warning. Anyone with the smallest inkling of common sense would know that backups stand a chance of not working right, just look at the ones for MS.

  10. #20
    Join Date
    Mar 2010
    Beans
    40

    Question Re: Easy Way To Backup Your System!! (Bash Script)

    yeah...I will put a warning on the main page.
    The thing is man, as i said, i'm not, nor am I claiming to be, a professional programmer.
    Anyone who wants something better can do so, and anyone wanting to keep their stuff more secure will no doubt have the ability to encrypt their files in a backup. Or at least the ability to learn how to do so.
    This is just aimed at people who don't know any better or who, like my dad for instance, don't want to spend time learning a new OS from start-to-finish and just want it to "work".
    I never claimed this to be flawless, but hell no script is completely without fault.

    anyway, it's not as if anyone is going so sue me.
    I have nothing. and i mean NOTHING.
    So if you are thinking of suing me- think again. you will only cause yourself some significant financial loss.

    I'd like you to give me a few examples of these problems you're talking about, and how you discovered them. Just for personal interest.

    thx.

    !!! VIVA LA LINUX !!!

    lonewaster
    Last edited by lonewaster; March 7th, 2010 at 09:16 PM.

Page 2 of 4 FirstFirst 1234 LastLast

Tags for this Thread

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
  •