Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Allow backup hosts to specify their own destination directory #1

Merged
merged 1 commit into from over 2 years ago

2 participants

David Lundgren Jason Rust
David Lundgren

Use 'destination' in the backup host configuration to set a different directory for the backups to be stored.

I also fixed some whitespace issues on accident due to my use of tabs.

David Lundgren dlundgren [FEATURE] Backup hosts can override the global destination directory
Use 'destination' in the backup host configuration to set a different directory for the backups to be stored.
cdec7b1
Jason Rust jrust merged commit 1b882db into from
Jason Rust jrust closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 12, 2012
David Lundgren dlundgren [FEATURE] Backup hosts can override the global destination directory
Use 'destination' in the backup host configuration to set a different directory for the backups to be stored.
cdec7b1
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 33 additions and 19 deletions. Show diff stats Hide diff stats

  1. +33 19 ribs
52 ribs
@@ -67,6 +67,7 @@ $s_destinationDir = dirname(__FILE__) . '/backups/';
67 67 * 'ip' => 'server ip address/FQDN',
68 68 * 'ssh_user' => 'the ssh user to use for rsync',
69 69 * 'ssh_port' => 'the ssh port (optional, defaults to 22)',
  70 + * 'destination' => 'overrides the global destination directory',
70 71 * 'directories' => 'backup directories separated by a space WITHOUT a trailing slash (i.e. /home /root)',
71 72 * If a directory has a space in it, escape it with a \
72 73 * 'excludes' => 'the directories to exclude separated by a space.
@@ -310,8 +311,8 @@ if ($a_configNames[0] == 'ALL') {
310 311 }
311 312
312 313 if ($b_reinit) {
313   - reInitBackups();
314   - exit;
  314 + reInitBackups();
  315 + exit;
315 316 }
316 317
317 318 if (empty($options[1][1])) {
@@ -406,7 +407,16 @@ foreach ($a_configNames as $s_configName) {
406 407 continue;
407 408 }
408 409
409   - $s_fullPath = $s_destinationDir . $s_configName . '/';
  410 + $s_backupDir = $s_destinationDir;
  411 + if (isset($a_backupHosts[$s_configName]['destination'])) {
  412 + $s_backupDir = $a_backupHosts[$s_configName]['destination'];
  413 + if (!is_dir($s_backupDir)) {
  414 + mkdir($s_backupDir, $s_defaultDirPerms);
  415 + $s_log .= writeln("Created destination directory: $s_backupDir", true);
  416 + }
  417 + }
  418 +
  419 + $s_fullPath = $s_backupDir . $s_configName . '/';
410 420
411 421 if (!is_dir($s_fullPath)) {
412 422 mkdir($s_fullPath, $s_defaultDirPerms);
@@ -660,10 +670,10 @@ foreach ($a_configNames as $s_configName) {
660 670
661 671 // send off the logs
662 672 if ($b_error) {
663   - mailAndLog($s_log);
  673 + mailAndLog($s_log);
664 674 }
665 675 else {
666   - mailAndLog();
  676 + mailAndLog();
667 677 }
668 678
669 679 exit;
@@ -744,35 +754,39 @@ function mailAndLog($in_errorMessage = false)
744 754 */
745 755 function reInitBackups()
746 756 {
747   - global $a_backupHosts, $a_configNames, $s_log, $s_destinationDir, $s_rm;
  757 + global $a_backupHosts, $a_configNames, $s_log, $s_destinationDir, $s_rm;
748 758
749   - writeln('Beginning Re-initialization.');
750   - foreach ($a_configNames as $s_configName) {
  759 + writeln('Beginning Re-initialization.');
  760 + foreach ($a_configNames as $s_configName) {
751 761 // make sure that we are using a valid configuration
752 762 if (!isset($a_backupHosts[$s_configName])) {
753 763 writeln("WARNING: The configuation: '$s_configName' is not valid, skipping it.\n", false, true);
754 764 continue;
755 765 }
756 766
757   - $answer = '';
758   - $s_fullPath = $s_destinationDir . $s_configName . '/';
759   - writeln ("Are you sure you want to re-initialize $s_configName?", false, true);
  767 + $s_backupDir = $s_destinationDir;
  768 + if (isset($a_backupHosts[$s_configName]['destination'])) {
  769 + $s_backupDir = $a_backupHosts[$s_configName]['destination'];
  770 + }
  771 +
  772 + $s_fullPath = $s_backupDir . $s_configName . '/';
  773 + writeln ("Are you sure you want to re-initialize $s_configName?", false, true);
760 774 echo 'This will completely remove it\'s backup directory and start from scratch. [y/n]: ';
761   - $answer = trim(readline());
762   - if ($answer == 'y' || $answer == 'Y') {
  775 + $answer = trim(readline());
  776 + if ($answer == 'y' || $answer == 'Y') {
763 777 exec("$s_rm -rf $s_fullPath");
764 778 writeln('Successfully re-initialized ' . $s_configName . '.');
765 779 continue;
766   - }
767   - elseif ($answer == 'n' || $answer == 'N') {
  780 + }
  781 + elseif ($answer == 'n' || $answer == 'N') {
768 782 writeln('Skipping re-initialization of ' . $s_configName . '.');
769 783 continue;
770   - }
771   - else {
  784 + }
  785 + else {
772 786 writeln('Aborting re-initialization.');
773 787 exit;
774   - }
775   - }
  788 + }
  789 + }
776 790
777 791 writeln('Re-initialization complete.');
778 792 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.