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

Thread: Simple backup script

  1. #11
    Join Date
    Jan 2009
    Location
    South Carolina
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Simple backup script

    Quote Originally Posted by monkeybrain20122 View Post
    I have not used rsync but I suppose it is /dev/sdg1 because you want the partition.

    It seems that the command only does one way backup. Does it overwrite the old copy or does it just change files that have been modified? What if you accidentally delete something and want to restore it from the backup (i.e syncing the other way around)? I am sure rsync has options for all these stuffs, it is quite widely used, but I haven't read its manual..
    /dev/sdg1 is a special device file for the drive, not a mountpoint.

    rsync has many options, and can be configured to do anything mentioned above.

  2. #12
    Join Date
    Apr 2006
    Beans
    497

    Re: Simple backup script

    Earlier I had witnessed my wife transferring files from the hdd to the USB drive (an Iomega portable), so I knew it should show up. So I drew on my Windoze training, and restarted the computer. Opened Nautilus again and clicked on the drive. Voila, there it was.

    So ntfs-3g was already installed somehow (Ubuntu Software Center confirms.)

    OK, so I found the drive at /media/Iomega_HDD.

    However this is a very good time to look into the question raised by MonkeyBrain. My wife has just become an Ubuntu user at my insistance because I just can't put up with Windows any longer and don't want to try to support her Windows computer with a dwindling Win knowledge. So this USB drive was created under Windows and may well need to be hooked up to the one remaining Windows computer sometime in future, so it retains the ntfs filessys.

    As mentioned in the original post, there are files already on the USB drive that need to be retained. So whatever my first instance of rsync is, it must not overwrite everything on the USB drive.

    Ideally the first run should just copy anything not already on the USB drive and add to it in the same name folder that each file is being copied from, and ideally set the flags so the any future updates only copies new or changed files from the source.

    As always, I dutifully have a dazed read of the man rsync pages (and am happy to report for the first time ever, some of it seems to be in English rather than Greek). But still over my head nonetheless.

    So as I understand it the backup.desktop file should read:
    Code:
    [Desktop Entry]
    Type=Application
    Name=backup script
    Exec=rsync -av /home/susie/desktop/susiefiles /media/Iomega_HDD
    Name=Backup
    1) totally clueless as to what the two (seemingly duplicate) "Name=" lines do. Are both needed?

    2) do the qualifiers "-av" accomplish my objective with respect to the first instance mentioned above?

    3) 2) do the qualifiers "-av" accomplish my objective with respect to the subsequent instances mentioned above?

    4) Finally, the folders containing the files being copied from already exist on the USB drive, as do 99.8% of the files on the source. Is the above going to put the "new" files from the source into the correct place on the target?

    Thanks for your patience and assistance on all of this.

  3. #13
    Join Date
    Jan 2009
    Location
    South Carolina
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Simple backup script

    Quote Originally Posted by Odyssey1942 View Post
    So as I understand it the backup.desktop file should read:
    Code:
    [Desktop Entry]
    Type=Application
    Name=backup script
    Exec=rsync -av /home/susie/desktop/susiefiles /media/Iomega_HDD
    Name=Backup
    1) totally clueless as to what the two (seemingly duplicate) "Name=" lines do. Are both needed?

    2) do the qualifiers "-av" accomplish my objective with respect to the first instance mentioned above?

    3) 2) do the qualifiers "-av" accomplish my objective with respect to the subsequent instances mentioned above?

    4) Finally, the folders containing the files being copied from already exist on the USB drive, as do 99.8% of the files on the source. Is the above going to put the "new" files from the source into the correct place on the target?

    Thanks for your patience and assistance on all of this.
    1: I believe the first name could/should be replaced with "Comment". This is the text that pops up when you hover over the icon.

    2: The -a switch includes the following other switches:
    Code:
        -r, --recursive recurse into directories
    
        -l, --links copy symlinks as symlinks
    
        -p, --perms preserve permissions
    
        -t, --times preserve modification times
    
        -g, --group preserve group
    
        -o, --owner preserve owner (super-user only)
    
        -D same as --devices --specials
    
        --devices preserve device files (super-user only)
    
        --specials preserve special files
    3: rsync will not overwrite your drive.

    4: Yes, however you must be careful with trailing slashes. I'd suggest playing around with rsync locally before you get the backups going.

    For instance,
    Code:
    rsync -av /home/user/directory/ /media/drive
    will copy the contents of /home/user/directory/ into the root of /media/drive, and not into a new directory on /media/drive.
    So, if you look in /media/drive, you will see all the files inside /home/user/directory.

    However,
    Code:
    rsync -av /home/user/directory /media/drive
    will copy the directory /home/user/directory into the root of /media/drive
    So, if you look in /media/drive, you will see the directory that you copied, and inside you will see the files.

    I hope this clears some things up; if you have any questions I'm here.
    Last edited by ubudog; February 12th, 2014 at 02:27 AM.

  4. #14
    Join Date
    Sep 2013
    Beans
    24

    Re: Simple backup script

    Code:
    #!/bin/bash
    
    ##### Begin Script #####
    
    backup()
    {
        if mountpoint -q $2 ; then
            rsync -au --delete $1 $2
        fi
    }
    
    
    while true
    do
        backup /folder/to/backup /mount/point/of/bu/drive
        sleep 120
    done
    
    ##### End Script #####
    For this to work you would need to set up the fstab with a uuid of the backup drive with a specific mount location. The script runs every 2 minutes (120 seconds.) Checks if mounted, if mounted runs backup. If it isn't mounted it doesn't do anything except sit until it checks for mountpoint again in 2 minutes. Fully automated just set this to run at boot and leave it alone.

    Note : Only use this if you want your external drive mirroring your working drive location. If you want multiple backups that is another matter. If you want it to only backup but never delete anything from the backup drive remove the --delete flag.
    Last edited by Jason_Gibson; February 12th, 2014 at 03:11 AM.

  5. #15
    Join Date
    Apr 2006
    Beans
    497

    Re: Simple backup script

    Jason, This is exactly the sort of thing I was hoping for. With thanks to Ubudog, I was getting a bit muddled and quite unsure whether I was going to create grief.

    Yes, I only want to backup (one-way) from the hdd to the one external USB drive, and as mentioned earlier want to take care not to erase any files or overwrite unchanged files on the USB.

    What I am still a bit unsure of is whether the "backup" command below:

    (a) is correct as I have modified it [all her "source" data folders and files are within "SusieStuff"],

    (b) will add new or changed files from existing folder 1 under SusieStuff on the HDD to the existing folder under SusieStuff 1 on the USB, and from folder 2 under SusieStuff on the HDD to the existing folder 2 under SusieStuff on the USB, etc, [i.e., don't want to somehow create 2 folders of the same name on the USB, one old, one new], as well as

    (c) will create any folders not now existing on the USB that do now exist on the HDD (i.e. very recently created folders) and adding any files within to the new folder on the USB?

    Another thing I am unclear on, since I would prefer not to overwrite any existing files on the USB, does removing "--delete" prevent this from happening, both first time and subsequent?

    Also, I have again consulted the man rysnc pages about $1 and $2 but did not see anything. I removed the "--delete" but should I also remove $1 and $2 in that same line as well (i.e., I don't understand their function)?

    Also note that I have changed the frequency to 10 mins.

    Here is the code that I plan to put into backup.susiestuff

    #!/bin/bash

    ##### Begin Script #####

    backup()
    {
    if mountpoint -q $2 ; then
    rsync -au $1 $2
    fi
    }


    while true
    do
    backup /home/susie/desktop/SusieStuff /media/Iomega_HDD
    sleep 600
    done

    ##### End Script #####
    For clarification, it is as close to a certainy as I can control, that there will be no files on the USB that are newer than, or have later modification dates than the files on the HDD. So it is entirely a one-way operation. In the man pages, it says about the qualifer "u":

    This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file.
    Since this should never happen, is "u" a qualifier I need?

    Finally, if the qualifier is -av instead of -au, where will the verbose output show up? Will she need to already have a terminal window open, or will rsync open one to display progress?

    Thanks.

  6. #16
    Join Date
    Aug 2013
    Beans
    3,034

    Re: Simple backup script

    Why don't you just give unison a try? Takes you a minute to figure out how to use it. If it doesn't suit your need just sudo apt-get remove unision-gtk. It is really easy.

  7. #17
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    2,804

    Re: Simple backup script

    There is also a graphical version of rsync called grsync in the Ubuntu Software Center. Just browse to the folder to be backed up and then browse to the destination, set your options by checking boxes and go. There is also an button for a trial run.

  8. #18
    Join Date
    Apr 2006
    Beans
    497

    Re: Simple backup script

    MB, I had already installed Unison and had a quick look, but it was not obvious to me how to get started. Didn't spend much time as I will get back to it later. I did look at a YouTube video of a "how to install", but it confirms that it looks like a new project.

    I also installed grsync, but again the setup looks like a learning curve.

    So I am just going to continue with rysnc as a script as I feel I am very close to implementation. If anyone can respond to my last post (long, but not complicated, apologies), which if carefully read is pretty narrow on a point by point basis, I think I will be ready to set it up.

  9. #19
    Join Date
    Aug 2013
    Beans
    3,034

    Re: Simple backup script

    Quote Originally Posted by Odyssey1942 View Post
    MB, I had already installed Unison and had a quick look, but it was not obvious to me how to get started. Didn't spend much time as I will get back to it later. I did look at a YouTube video of a "how to install", but it confirms that it looks like a new project.
    It is not a new project. In fact it has stopped active development but since the developers use it themselves there will be updates if there are major bugs.

    To use it is very easy. First open the interface, click add to create a new profile, then enter the folders to be sync and that's it. If you sync with an external device then of course it has to be mounted first. To use it just mount the external device, start unison, choose profile from the list of profiles you created and click "open", when it finishes its calculation, click "go" and that's it. As I said the default is to sync according to the most recent modifications, but you can override it if you wish (use the buttons "left to right" and "right to left"). See the screenshots, the second one should be the last, I added it later and the order messed up. (you need to install unison-gtk)
    Last edited by monkeybrain20122; February 13th, 2014 at 03:17 AM.

  10. #20
    Join Date
    Apr 2006
    Beans
    497

    Re: Simple backup script

    MB, my apology as I meant it was a new project for me to learn it. Maybe simple, maybe not. For example, I do not know what a profile is and have no idea which of the boxes I should check or not and will need to google and read so as to make good choices, etc.

    As much a beginner as I am, my wife is way back from me If I asked her to explain what an O/S is, or what a terminal is, she would not even know what I am talking about. So this needs to be either a one click process, or better a totally automated one, such as the script that Jason kindly provided. From what I understood of what you wrote, it does not seem to be an automated process (e.g., "then of course it has to be mounted first.")

    I really do plan to spend some time on both Unison and grsync, but for now, I want to get her files backed up as efficiently and expediently as possible, starting as soon as possible. So for now, finishing the script is my priority. Thanks again for your good suggestion, which I will indeed follow up on, and soon.

Page 2 of 4 FirstFirst 1234 LastLast

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
  •