The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sync directories on 2 accounts (one server), both ways

Discussion in 'General Discussion' started by GoWilkes, Jul 7, 2012.

  1. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I have a semi-managed server with one account: mine. I'm working on a redesign that's temporarily under a new domain name and new account on the same server. I'm using the new account as a beta for a few weeks, and then will eventually delete the original account.

    The problem I'm having is that both accounts will be active while it's in beta, which means that users can upload files and images to either account. Eg, old account:

    /home/original/www/cache/
    /home/original/www/classifieds/photos/
    /home/original/www/private_message/attachments/

    New account:

    /home/new/www/cache/
    /home/new/www/classifieds/photos/
    /home/new/www/private_message/attachments/

    There are 14 directories like this.

    I've looked for a way to modify my Perl scripts to allow the user to upload to both accounts, but haven't found anything, so I guess that I have to resort to a cron to copy files over every minute.

    That's far from ideal since (a) it means that a minute will go by with no file on one of the servers, and (b) I'm going to have a significantly increased server load to run a cron like this every minute. So if anyone has a better suggestion, I'm all ears.

    But assuming that I'll have to do this with a cron, my question is this: how can I synchronize the accounts both ways? I'm finding plenty of ways to copy all files from A to B, but I also need to make sure that files are copied from B to A. Meaning, if they are on B and upload, then I need the file to show up on A, too.

    If I simply do this:

    rsync -au /home/original/cache/ /home/new/cache

    then it would just copy files from /original/ to /new/, which means that I need to run a second cron to go the other direction:

    rsync -au /home/new/cache/ /home/original/cache

    With 14 directories, that's 28 "cp" commands that I'll need to run, every minute. That seems excessive.

    Is there a better way to do this?
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Which PHP handler are you using? If you are using DSO, you could just symlink the second account's directory to the other account. If you are using suPHP, you'd have to disable fileprotect to allow that to work.
     
  3. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I'm using DSO, so I think you're right about the symlink. I didn't think that doing that would allow me to write from /new/ to /original/, but if it does then that's awesome!

    I've only done that once (a year or two ago), so can you confirm that I'm doing it correctly?

    On the new account, I would create /home/new/www/cache/. Question: do I need to chmod to 666, or is the permission for /original/ the only one that matters?

    Then, in SSH as root:

    ln -s /home/original/www/cache/ /home/new/www/cache/

    That's:

    "ln" to create the link
    "-s" to make it symbolic
    "/home/original/www/cache/" the original directory to which the new directory is going to link
    "/home/new/www/cache/" as the new directory that's going to become the symlink


    I'm always a little nervous with root commands on a live server (with my limited knowledge, I'm always afraid that a typo will get me into a position that I can't back out of), so thanks for glancing at it and making sure that I don't have the equivalent of a "rm *" command in there :)
     
    #3 GoWilkes, Jul 9, 2012
    Last edited: Jul 9, 2012
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    You are correct for everything other than creating /home/new/www/cache folder. The folder that is a link to the original one can't exist already, so you wouldn't create it. Also, I'd use the real paths of public_html rather than www as www is a symlink itself to public_html, so instead just SSH and do:

    ln -s /home/original/public_html/cache /home/new/public_html/cache

    The symlink should itself create the /home/new/public_html/cache folder.
     
  5. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I set up the symlink successfully, and it's working... kinda. I can read the files in the directory, but I can't write to them. And when I try to enter the directory via FTP, I'm getting "permission denied".

    In order to read, I had to change the owner, too:

    ln -s /home/original/public_html/cache /home/new/public_html/cache
    chown -hR original.original /home/new/public_html/cache

    I should mention that the permission of /original/public_html/cache is 0777.

    I CAN enter the directory if I'm logged in as root, but not as "new" user.

    Any suggestions?
     
    #5 GoWilkes, Jul 10, 2012
    Last edited: Jul 10, 2012
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
  7. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I actually think we're on the right track with the symlink, there's just a permission or something that's keeping me from having write access.

    I emailed my server provider, and they suggested that I had "new" to the "original" group. I'm not entirely sure what that means; I'm vaguely familiar with the "Wheel Group", but his description makes me think that there's a separate "user group" of some sort.

    I couldn't find anything online, so I'm lost. Could I just modify /etc/group, like this?:

    original:x:502:new
     
  8. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    They are talking about the following:

    Howto: Linux Add User To Group

    You wouldn't ever modify /etc/group manually, so you'd do instead:

    Code:
    usermod -a -G original new
    I tried this on my machine and here are the results (where danielle is the group I am adding endar user to):

    Code:
    root@host [/]# usermod -a -G danielle endar
    root@host [/]# grep danielle /etc/group
    danielle:x:500:endar
     
  9. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Quick update:

    My server provider sent me an alternative that works perfectly for my purposes. They installed bindfs for me, via:

    yum install fuse-libs fuse
    rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/bindfs-1.8.3-3.el5.i386.rpm

    Then, it's a simple matter of deleting the "cache" symlink, creating a "cache" hard link, and then:

    bindfs -u new /home/original/public_html/cache /home/new/public_html/cache

    (Note: the "-u new" refers to the account name of "new")

    The description they gave me was that "this is more or less a mount --bind replacement that allows custom ownership". The "new" account will be the owner of all files in /home/new/public_html/cache, but each file is actually a file in /home/original/public_html/cache.

    For the sake of future readers, if you see where I went wrong with the symlink, then please still post it. But if others come across this stumbling block and can't get past it, then bindfs is an easy, quick alternative worth considering.
     
Loading...

Share This Page