+ Post New Thread
Results 1 to 15 of 15
*nix Thread, Can a script be triggered by an rsync backup? in Technical; I'm looking to backup a Moodle installation running on one virtual server, and a Joomla installation on another. I've tested ...
  1. #1
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39

    Can a script be triggered by an rsync backup?

    I'm looking to backup a Moodle installation running on one virtual server, and a Joomla installation on another. I've tested rsync to pull the data from one, then the other onto a physical backup server which works with no problems but ideally I don't want to have the MySQL databases pre-dumped in order to back them as they won't be in sync with the data. Is it possible to launch a trigger a script by initiating an rsync connection or would I have to make use some kind of remote execution script that would do all the prep work beforehand, then initiate the rsync connection. I want to keep it as simple as possible though so somehow getting the rsync daemon to dump the database seems the ideal way to do. It seems logical to me that something like rsync would have a pre and post transfer command option.

  2. #2
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    ...just found them I think.

    pre-xfer exec and post-xfer exec.

    Amazing what you learn by reading the instructions. :-)

  3. #3

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,934
    Thank Post
    1,628
    Thanked 1,898 Times in 1,410 Posts
    Blog Entries
    2
    Rep Power
    429
    they are the correct commands, i did it at another school and it works fine, but make sure that before you do it, take a full backup of your database just in case, i saw in our first try, every table got dropped and all data along with, we had to restore it and go through it 1 step at a time.

  4. #4
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    Do you mean that the first time you tried to use msqldump through a pre-xfer exec script that it dropped the tables for no reason?

  5. #5

    nephilim's Avatar
    Join Date
    Nov 2008
    Location
    Dunstable
    Posts
    11,934
    Thank Post
    1,628
    Thanked 1,898 Times in 1,410 Posts
    Blog Entries
    2
    Rep Power
    429
    yeah. you have to be careful and make sure you do not rush it. what we did was mis-coded the exec script, but for safety sake i made a backup before i started, something i do out of habbit.

  6. #6
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    Any idea why I can't stop Apache and MySQL from pre-xfer exec, but I can start them? The rsync daemon is running as root so I thought it would work. I've tried through inetd and running it directly from the console.

  7. #7

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    The simplest way to achieve this would be with a cron-called script. On Debian/Ubuntu systems:

    Code:
    set -e
    invoke-rc.d apache2 stop
    invoke-rc.d mysqld stop
    <your rsync stuff>
    invoke-rc.d mysqld start
    invoke-rc.d apache2 stop

  8. #8
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    I'm looking to pull from the servers to a backup server, rather than push onto a backup server so the backups are queued and don't overload the SAN (all servers except one are virtual). I'm thinking about backing up things like Moodle, I can dump the database in pre-xfer exec so it's up-to-date, but I wanted to stop the web services and so that someone couldn't be using it and modifying things while the file backup is running (as the the database would then be out of sync with the data). Or should I not worry about that happening?

  9. #9
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    Out if interest, was does 'set -e' do?
    And what does invoke-rc.d do that is different from using /etc/init.d/apache2 stop
    I'm am using Debian (Lenny).

  10. #10

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Quote Originally Posted by morganw View Post
    Out if interest, was does 'set -e' do?
    Causes bash to halt if it encounters an error with any of the commands.

    Quote Originally Posted by morganw View Post
    And what does invoke-rc.d do that is different from using /etc/init.d/apache2 stop
    From the manual:

    Quote Originally Posted by sid
    invoke-rc.d is a generic interface to execute System V style init
    script /etc/init.d/name actions, obeying runlevel constraints as well
    as any local policies set by the system administrator.
    Quote Originally Posted by morganw View Post
    I'm am using Debian (Lenny).
    An excellent choice


    Quote Originally Posted by morganw View Post
    I'm looking to pull from the servers to a backup server, rather than push onto a backup server so the backups are queued and don't overload the SAN (all servers except one are virtual). I'm thinking about backing up things like Moodle, I can dump the database in pre-xfer exec so it's up-to-date, but I wanted to stop the web services and so that someone couldn't be using it and modifying things while the file backup is running (as the the database would then be out of sync with the data). Or should I not worry about that happening?
    Well if you really want to co-ordinate this centrally you have three options as I see it:

    a) use ssh on the backup server to log in to each server in turn for the service commands, and do your rsync from there;
    b) use ssh on the backup server to run a local script on each server in turn, which pushes the backup to the server;
    c) space out the backups overnight, so each server gets a chance at running full pelt (every other hour, for example).

  11. Thanks to powdarrmonkey from:

    morganw (17th June 2010)

  12. #11
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    I would go for a) but I also need to backup windows servers and don't want to install anything like cygwin.
    Are there no permissions I could modify to allow the rsync daemon to stop apache? I guess I can automate a VM snapsnot as well to try and get a more complete backup if it can't be done.

  13. #12

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,762
    Thank Post
    3,271
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365
    Quote Originally Posted by morganw View Post
    ...just found them I think.

    pre-xfer exec and post-xfer exec.

    Amazing what you learn by reading the instructions. :-)
    LOL - was wondering why they called it RTFM aka read the fine manual ( polite version )

  14. #13

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,762
    Thank Post
    3,271
    Thanked 1,053 Times in 974 Posts
    Rep Power
    365
    Quote Originally Posted by morganw View Post
    I would go for a) but I also need to backup windows servers and don't want to install anything like cygwin.
    Are there no permissions I could modify to allow the rsync daemon to stop apache? I guess I can automate a VM snapsnot as well to try and get a more complete backup if it can't be done.
    Not really familiar with *nix yet but curious is there something equivalent to WMI where you could monitor for a specific process ending or finishing and then once it finishes to do something else prior to or afterwards ?

  15. #14

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    I guess if you really want an absolute snapshot of the state of the machine, that's what you have to do... I don't think you need to be so precise though, why don't you have pre-xfer do a mysqldump? It won't take long, and in the middle of the night the chances of something being uploaded that the database doesn't know about are minute.

  16. #15
    morganw's Avatar
    Join Date
    Apr 2009
    Location
    Cambridge
    Posts
    816
    Thank Post
    46
    Thanked 132 Times in 126 Posts
    Rep Power
    39
    Quote Originally Posted by powdarrmonkey View Post
    I guess if you really want an absolute snapshot of the state of the machine, that's what you have to do... I don't think you need to be so precise though, why don't you have pre-xfer do a mysqldump? It won't take long, and in the middle of the night the chances of something being uploaded that the database doesn't know about are minute.
    I guess the worst I could end up with would be files uploaded into Moodle that the database doesn't know about so they would be orphaned if I had to do a restore, but as you say the chances of it happening are minimal. I've found it pays to be paranoid though, the SAN is running RAID6 for my peace of mind but i'm trying to get a backup strategy that is the best it can be in the unlikely event that it suddenly bursts into flames.

    Thank you for the advice by the way and info by the way. Always keen to do more through linux and similar.

SHARE:
+ Post New Thread

Similar Threads

  1. Rsync X
    By ranj in forum Mac
    Replies: 2
    Last Post: 5th May 2009, 07:33 PM
  2. Help with Backup Script
    By soze in forum Scripts
    Replies: 5
    Last Post: 18th June 2008, 12:12 AM
  3. Backup PenDrive Script
    By SimpleSi in forum Scripts
    Replies: 9
    Last Post: 18th January 2007, 02:45 PM
  4. Backup Perl Script
    By ranj in forum Scripts
    Replies: 1
    Last Post: 30th April 2006, 08:02 PM
  5. Backup Script for NT backup and Robocopy
    By ChrisH in forum Scripts
    Replies: 12
    Last Post: 20th October 2005, 01:01 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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