From: Rene R. <ren...@us...> - 2003-12-29 02:43:41
|
Update of /cvsroot/bobs/bobs/inc In directory sc8-pr-cvs1:/tmp/cvs-serv25408/inc Modified Files: class_backup.php class_server.php config.php.in Log Message: Adding rsync_ssh backup_method from Jochen Metzger. Added admin help page. Index: class_backup.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_backup.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- class_backup.php 3 Apr 2003 00:23:31 -0000 1.8 +++ class_backup.php 29 Dec 2003 02:43:28 -0000 1.9 @@ -26,6 +26,15 @@ var $session_id = ''; // unique session id var $filelinks = ''; // files that are linked (depend on each other) var $rsync_share = ''; // name of the rsync share + + /* 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 + var $smb_share = ''; // name of the smb share var $backup_method = ''; // backup method (smb/nfs/rsync) var $restore_method = ''; // restore method (smb/nfs) @@ -59,9 +68,15 @@ $this->password = $vol_conf["password"]; $this->login = $vol_conf["login"]; $this->rsync_share = $vol_conf["rsync_share"]; - $this->restore_method = $vol_conf["restore_method"]; - + /* 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"]; $this->filelinks = parse_ini_file($this->siteroot . '/inc/filelinks.ini', process_sections); @@ -145,6 +160,11 @@ case "rsync": $this->rsync_backup($exclude_from); break; + + case "rsync_ssh": + $this->rsync_ssh_backup($exclude_from); + break; + case "nfs"; $this->nfs_backup($exclude_from); break; @@ -152,7 +172,9 @@ } - + /* classic way -> rsync using an daemon + * which has to run !!! on the remote side (backuped side) + */ function rsync_backup ($exclude_from) { // make backup using rsync @@ -170,7 +192,7 @@ */ // put together the script we need to execute - $backupcommand = 'rsync -e ssh --archive --verbose --delete --backup ' ; + $backupcommand = 'rsync --archive --verbose --delete --backup ' ; $backupcommand .= $exclude_from; $backupcommand .= '--backup-dir="' . $this->incomingdir . '/' . $this->server . '/' . $this->share . '/"' ; @@ -194,6 +216,53 @@ $this->add_queue_command($shell, "bash"); return $result; + } + + + /* 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: class_server.php =================================================================== RCS file: /cvsroot/bobs/bobs/inc/class_server.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- class_server.php 19 May 2003 00:11:39 -0000 1.6 +++ class_server.php 29 Dec 2003 02:43:28 -0000 1.7 @@ -31,7 +31,8 @@ foreach ( $this->servers as $server ) { $cur_server = $server["server"] . '.' . $server["share"]; - if ( $cur_server == $login_server && $server["password"] == $login_password ) { + if ( $cur_server == $login_server && $server["password"] == $login_password + && $server["restore_method"] != "none") { // not allowed to login, when restore_method == "none" $this->login_ok = 'yes'; $this->config = $server; return; Index: config.php.in =================================================================== RCS file: /cvsroot/bobs/bobs/inc/config.php.in,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- config.php.in 28 Jun 2003 06:45:49 -0000 1.8 +++ config.php.in 29 Dec 2003 02:43:28 -0000 1.9 @@ -49,13 +49,18 @@ $server_defs["backup_method"]["type"] = "list"; $server_defs["backup_method"]["desc"] = "Method for creating backups"; $server_defs["backup_method"]["list"]["0"] = "rsync"; -$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"; + + + $server_defs["restore_method"]["type"] = "list"; $server_defs["restore_method"]["desc"] = "Method for restoring files"; $server_defs["restore_method"]["list"]["0"] = "nfs"; $server_defs["restore_method"]["list"]["1"] = "smb"; +$server_defs["restore_method"]["list"]["2"] = "none"; $server_defs["smb_share"]["type"] = "text"; $server_defs["smb_share"]["desc"] = "Name of the smb share"; @@ -87,6 +92,21 @@ $server_defs["rsync_share"]["depends"]["name"]["0"] = "backup_method"; $server_defs["rsync_share"]["depends"]["value"]["0"] = "rsync"; $server_defs["rsync_share"]["depends"]["rule"]["0"] = TRUE; + + +/* 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 */ $server_defs["incrementals"]["type"] = "number"; $server_defs["incrementals"]["desc"] = "How many incremental backups to keep (0 = infinite)"; |