|
From: Jochen M. <ml...@om...> - 2003-12-28 18:45:47
|
Hi,
as I needed rsync over ssh for my environment I have implemented it.
I have decided myself to implement it as extra "backup_method".
This way everything else stays untouched.
In my thread "..bobs for internet services.." you can find a description
of how ssh and rsync work together.
rsync as implemented in the current cvs-bobs version did not go over
ssh, because the daemon - option, started by using "::" in the
commandline was stronger. So the "-e ssh"-option was "though present"
not used.
You can either use rsync over a daemon or ssh.
Because there were some differences in the current implemented
"daemon"-rsync version in bobs, I decided to make up another
"backup method" to make it less complicated.
The differences are:
1. rsync over ssh does not use sharenames (which were defined in
rsyncd.conf), you can just use the absolute paths (e.g. /path/to/dir)
2. You need a username which you use for connection
(Of course one could use the login name, but I didn't want to
use that, because it could be different in the "Internet Servers"
case. If a user later on should have the ability to restore things
he should have restricted rights, but a rsync user should probably
have more rights to set ownerships etc.
Additional restore_method:
==========================
restore_method : "none"
Backing up from internet servers, I found NFS and smb to insecure, so I
decided myself to set the restore_method to none.
I found this the easiest way. When setting this, you cannot log in to
the restore area, cause you cannot choose those server who have restore
method none.
I know, this is just an interims solution. As mentioned in a mail before
it would be a nice way to use rsync as well to restore the files.
(making the access from the backup server to the remote server)
But I wanted to have a quick workaround.
It is not really secure, because the server just does not turn up in the
select (under http://bobsdomain/bobs/) that all. Of course you could log
in by setting the correct vars in the request.
So know I have been writing a lot. Unfortunately I could not get one of
you, so I could have talked about some stuff to get it clear.
So here is my version. As Joe adviced, I checked out an cvs version and
made the changings (and testet them several times - they work / I put
them in the sources and made an installation (configure and make
install))
The I made the diffs. I tried to change as little as possible.
So here the diffs are:
I hope that you like it. I am reading that list. So if some question are
coming up, I am ready to answer them
Cheers
Jochen Metzger
Index: admin.php
===================================================================
RCS file: /cvsroot/bobs/bobs/admin.php,v
retrieving revision 1.24
diff -r1.24 admin.php
280a281,283
> // avoid that "/" is used in Share name
> if (substr_count($share,"/") > 0)
> return "'/' is not allowed in the Share name (suggestion:
use '_' instead)";
358a362,368
>
> if (($settings['backup_method'] =='rsync_ssh')
> && (trim($settings['rsync_ssh_path']) == "")){
> return "Please specify the directory to backup on the rsync
Remote Server.";
>
> }
>
Index: index.php
===================================================================
RCS file: /cvsroot/bobs/bobs/index.php,v
retrieving revision 1.5
diff -r1.5 index.php
69,81c69,99
< echo '<form name="loginform" method="POST">';
< echo "<p><big>Select the server and share you wish to
use</big><br><br>";
< echo '<select name="server">';
< foreach ( $srvcfg->servers as $server ) {
< echo '<option value="' . $server["server"] . '.' .
$server["share"] . '">' . $server["server"] . ' / ' . $server["share"];
< }
< echo '</select></p>';
< echo '<p><big>Type the login name for the selected
server</big><br><br> <input type="text" value="login name"
name="loginname"></p>';
< echo '<p><big>Type the password for the selected
server</big><br><br> <input type="password" name="password"></p>';
< echo '<p><big>Press the Login button to
continue</big><br><br><input type="submit" name="login"
value="Login"></p>';
< echo '<input type="hidden" name="trylogin">';
< echo '</form>';
< ?>
---
> if (is_array($srvcfg->servers)){
>
> echo '<form name="loginform" method="POST">';
> echo "<p><big>Select the server and share you wish to
use</big><br><br>";
>
> echo '<select name="server">';
> foreach ( $srvcfg->servers as $server ) {
> if ($server["restore_method"] != "none")
> $options.='<option value="' . $server["server"] . '.' .
$server["share"] . '">' . $server["server"] . ' / ' .
$server["share"]."</option>";
> }
>
> if ($options == ""){
> $options.='<option value="">No Servers with Restore Ability
present</option>';
> }
>
> echo $options;
>
> echo '</select></p>';
> echo '<p><big>Type the login name for the selected
server</big><br><br> <input type="text" value="login name"
name="loginname"></p>';
> echo '<p><big>Type the password for the selected
server</big><br><br> <input type="password" name="password"></p>';
> echo '<p><big>Press the Login button to
continue</big><br><br><input type="submit" name="login"
value="Login"></p>';
> echo '<input type="hidden" name="trylogin">';
> echo '</form>';
>
> }
> // show up when no servers are configured yet
> else {
> echo '<big>No servers configured yet.<br><a
href="admin.php">Configure Servers</a></big>';
> }
>
> ?>
Index: inc/class_backup.php
===================================================================
RCS file: /cvsroot/bobs/bobs/inc/class_backup.php,v
retrieving revision 1.8
diff -r1.8 class_backup.php
28a29,37
>
> /* new stuff for rsync_ssh */
> var $rsync_ssh_path = ''; // name of the rsync path on
the remote server
> // ssh only works with pathes
and not share on the remote server
> var $rsync_ssh_user = 'root'; // 'root' is default
> // user used for connection
by ssh
> // additional a public (on
remote server)/ private key (on backup server)
> // pair must be given
>
62d70
< $this->restore_method = $vol_conf["restore_method"];
64c72,79
<
---
> /* new stuff for rsync_ssh */
> $this->rsync_ssh_path = $vol_conf["rsync_ssh_path"];
>
> /* only use when set, else stay default */
> if (trim($vol_conf["rsync_ssh_user"]) != "")
> $this->rsync_ssh_user = $vol_conf["rsync_ssh_user"];
>
> $this->restore_method = $vol_conf["restore_method"];
147a163,167
>
> case "rsync_ssh":
> $this->rsync_ssh_backup($exclude_from);
> break;
>
155c175,177
<
---
> /* classic way -> rsync using an daemon
> * which has to run !!! on the remote side (backuped side)
> */
173c195
< $backupcommand = 'rsync -e ssh --archive --verbose
--delete --backup ' ;
---
> $backupcommand = 'rsync --archive --verbose --delete
--backup ' ;
196a219,265
> }
>
>
> /* rsync_ssh used to backup with rsync over ssh */
> function rsync_ssh_backup($exclude_from){
>
> // make backup using rsync over ssh
>
> // command to run, put ' > /dev/null &' at the end to
free the process and block output
>
> /*
> options used for rsync
> --archive = archive mode
> --verbose = verbose execution
> --delete = delete files from
backup when deleted on the original site
> --backup = make backups
> --backup-dir=DIR = move backups into this
dir
> --exclude-from=FILE = exclude files listed
in this file
> */
>
> // put together the script we need to execute
> $backupcommand = 'rsync -e ssh --archive --verbose
--delete --backup ' ;
> $backupcommand .= $exclude_from;
> $backupcommand .= '--backup-dir="' . $this->incomingdir
. '/' . $this->server . '/' . $this->share . '/"' ;
>
> // need to check if we are using IP or DNS!!!!
> if ( $this->server_ip != '' ) {
> $backupcommand .= ' ' .
$this->rsync_ssh_user.'@'.$this->server_ip;
> } else {
> $backupcommand .= ' ' .
$this->rsync_ssh_user.'@'.$this->server;
> }
>
> // only one ":" when we use ssh
> $backupcommand .= ':' . $this->rsync_ssh_path . ' "' .
$this->backupdir . '/' . $this->server . '/' . $this->share . '/"';
>
> $shell = "#!/bin/sh\n";
> $shell .= "# Description: Backup files from server\n";
> $shell .= $backupcommand . "\n";
>
>
> $this->command = $shell ;
>
> // add the script to command queue
> $this->add_queue_command($shell, "bash");
>
> return $result;
>
Index: inc/config.php.in
===================================================================
RCS file: /cvsroot/bobs/bobs/inc/config.php.in,v
retrieving revision 1.8
diff -r1.8 config.php.in
52,53c52,57
< $server_defs["backup_method"]["list"]["1"] = "nfs";
< $server_defs["backup_method"]["list"]["2"] = "smb";
---
> $server_defs["backup_method"]["list"]["1"] = "rsync_ssh";
> $server_defs["backup_method"]["list"]["2"] = "nfs";
> $server_defs["backup_method"]["list"]["3"] = "smb";
>
>
>
58a63
> $server_defs["restore_method"]["list"]["2"] = "none";
89a95,109
>
>
> /* START OF ADDINGS for rsync_ssh */
> $server_defs["rsync_ssh_path"]["type"] = "path";
> $server_defs["rsync_ssh_path"]["desc"] =
"Directory on rsync Remote Host to backup (absolute / starting with
'/')";
> $server_defs["rsync_ssh_path"]["depends"]["name"]["0"] =
"backup_method";
> $server_defs["rsync_ssh_path"]["depends"]["value"]["0"] =
"rsync_ssh";
> $server_defs["rsync_ssh_path"]["depends"]["rule"]["0"] = TRUE;
>
> $server_defs["rsync_ssh_user"]["type"] = "text";
> $server_defs["rsync_ssh_user"]["desc"] =
"SSH-Connect with User (use 'root' by default)";
> $server_defs["rsync_ssh_user"]["depends"]["name"]["0"] =
"backup_method";
> $server_defs["rsync_ssh_user"]["depends"]["value"]["0"] =
"rsync_ssh";
> $server_defs["rsync_ssh_user"]["depends"]["rule"]["0"] = TRUE;
> /* END OF ADDINGS for rsync_ssh */
|