Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 67

Thread: Rsync - What's YOUR setup like?

  1. #11
    Join Date
    Apr 2009
    Beans
    1,173

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by Penguin Guy View Post
    Yes, run it as root, and make sure the permissions get preserved, but do a check to make sure the drive is mounted. As for how you do that, I'm not totally sure: google it.
    This cludge will check if something is mounted:

    Code:
    cat /proc/mounts | grep /media/BigBadBackup
    if [ $? -eq 1 ] ; then
      # BigBadBackup is mounted, so we can rsync to it
    fi
    But if you don't need to rsync as root, then don't run it as root. Using the minimum permission to get the job done is safer. You should use -a which is equivalent to all of -r recurse; -l copy symlinks as symlinks; -ptgo permissions, times, group and owner; and -D preserve device / specials if superuser. Using -a means your backup is pretty much identical to your original, and will function the same if restored.

  2. #12
    Join Date
    Jul 2006
    Beans
    4,860

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by StuartN View Post
    Using -a means your backup is pretty much identical to your original, and will function the same if restored.
    That's actually kind of what I want, to be honest.

    Is there any way we can break down that grep command so I understand it easier? I have 4 drives in my system, 2 of which are backups. 500/500gb and 250/250gb... the 500s are mine + backup and the 250s are samba network file storage + backup.

    The mount points are:

    /media/localbackup
    /media/storage
    /media/storagebackup

    Each command is:

    rsync -a --progress --delete /source /destination

    How would I incorporate that grep command into each individual rsync command, seeing as though I'm running 3 commands in a bin/bash script.

  3. #13
    Join Date
    Apr 2009
    Beans
    1,173

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by Roasted View Post
    Is there any way we can break down that grep command so I understand it easier?
    The first part, cat /proc/mounts, is a list of currently mounted filesystems - you could equally use the mount command. The output is piped into grep to search for a particular mountpoint.

    Note that your second mount at /mount/storage would also match your third at /mount/storagebackup, so add the -w (whole word) option to grep.

    The variable $? is (I think) a success flag. Whatever it is, echo $? shows you 0 if a command returned a result, or 1 if it did not - most commands return 0. Grep returns 0 if the string was matched and 1 if it was not.

    So we just check each mountpoint in turn and run rsync if it is present.

    Code:
    cat /proc/mounts | grep -w /media/localbackup
    if [ $? -eq 0 ] ; then
      rsync -a --progress --delete source1 /media/localbackup
    fi
    
    cat /proc/mounts | grep -w /media/storage
    if [ $? -eq 0 ] ; then
      rsync -a --progress --delete source2 /media/storage
    fi
    
    cat /proc/mounts | grep -w /media/storagebackup
    if [ $? -eq 0 ] ; then
      rsync -a --progress --delete source3 /media/storagebackup
    fi
    I have my backup script on the desktop to click whenever I want to feel like I have done something important. I could add it to crontab, but that would be too organized.
    Last edited by StuartN; October 14th, 2009 at 08:48 PM. Reason: My bad, should be [ $? -eq 0 ] and not [ $? -eq 1 ]

  4. #14
    Join Date
    Jul 2006
    Beans
    4,860

    Re: Rsync - What's YOUR setup like?

    Well, geez. I'm not exactly a programmer but that still is confusing to me.

    I just thought there would be an easier command to execute which first checks the mount point then pipes it to run. That was just my assumption though... something like:

    sudo if /media/localbackup exists | rsync -a --progress --delete /home/jason /media/localbackup

  5. #15
    Join Date
    Apr 2009
    Beans
    1,173

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by Roasted View Post
    Well, geez. I'm not exactly a programmer but that still is confusing to me.
    My apologies, I made a mistake in that example. The tests should all be [ $? -eq 0 ], that is run the rsync if the grep was successful and not [ $? -eq 1 ] which would run rsync if the grep failed (did not return any matches).

    NB: $? is set by every command, so echo $? is zero if the last command "succeeded", e.g. it is not zero after ls this_file_does_not_exist, which can be very useful.

  6. #16
    Join Date
    Jul 2006
    Beans
    4,860

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by StuartN View Post
    My apologies, I made a mistake in that example. The tests should all be [ $? -eq 0 ], that is run the rsync if the grep was successful and not [ $? -eq 1 ] which would run rsync if the grep failed (did not return any matches).

    NB: $? is set by every command, so echo $? is zero if the last command "succeeded", e.g. it is not zero after ls this_file_does_not_exist, which can be very useful.
    LOL. I wouldn't have known the difference any other way.

    So, say I didn't come here and get this help from you guys. What should I do then? Should I just run the script with root and just bank on hoping the drives stay active?

    I guess worst case scenario, if a drive DOES go down and the script kicks in anyway, it would just kick 300gb of data to the empty mount point, which would just dump it on my root partition and max it out. At that point all I should need to do is delete the data, or at worst - boot to a LiveCD and remove it from the unmounted mount point.

    Is my train of thought correct?

  7. #17
    Join Date
    Jul 2006
    Beans
    4,860

    Re: Rsync - What's YOUR setup like?

    New question - Is it possible to rsync to the drive itself rather than its mount point?

    /dev/sdb1 gets mounted to /media/localbackup

    I can rsync to /media/localbackup, I got that.

    But can I run my rsync to /de/sdb1?

    I was just thinking, if /dev/sdb1 goes down, it's gone, so if the rsync script kicks in, it won't see it, whereas it'll see /media/localbackup regardless of whether or not it's mounted cause it's still a folder where data can be put into.

  8. #18
    Join Date
    Apr 2009
    Beans
    1,173

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by Roasted View Post
    New question - Is it possible to rsync to the drive itself rather than its mount point?
    I am sure someone will correct me if I am wrong, but I would not think that rsync can handle a raw device. If the device has not been mounted then there is no protocol to write to it - i.e. rsync would have no knowledge of the filesystem, let alone any paths or access permissions.

  9. #19
    Join Date
    Jul 2006
    Beans
    4,860

    Re: Rsync - What's YOUR setup like?

    Quote Originally Posted by StuartN View Post
    I am sure someone will correct me if I am wrong, but I would not think that rsync can handle a raw device. If the device has not been mounted then there is no protocol to write to it - i.e. rsync would have no knowledge of the filesystem, let alone any paths or access permissions.
    /dev/sdb1 = /media/localbackup

    I tried my rsync script, but plugged in /dev/sdb1 for /media/localbackup and it barfed out a bunch of errors. So I guess the answer to that is a "no."

    Question - if I would utilize a program such as GRsync, would that program be able to detect if a HDD is active/mounted prior to executing the command? I'm just trying to find a more automated way to handle this, mostly because I want to make sure I do it right and these commands are kind of "whoa, wtf??" to me.

  10. #20
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: Rsync - What's YOUR setup like?

    I don't know if it will know if a device is mounted or not. What I did was mount my external to something like /sync and then run something like this:

    Code:
    rsync -ar /storage /sync
    -a = archive, copies all permissions and whatnot
    -r = recursive, copying everything recursively

Page 2 of 7 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
  •