Procházet zdrojové kódy

Updated Readme.md
Removed installation specific parameters from backup script

Sebastian Vendt (Manaslu) před 1 rokem
rodič
revize
b601f4006a
3 změnil soubory, kde provedl 38 přidání a 28 odebrání
  1. 1 0
      .gitignore
  2. 32 9
      Readme.md
  3. 5 19
      getRemoteBackup.sh

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 *.conf
+*.yaml

+ 32 - 9
Readme.md

@@ -1,12 +1,16 @@
 # Remote Backup Manager
-This script uses rsync to backup files from any source (e.g. Remote) to any target (usually the host, the script runs on). Once the 
+This script uses rsync to backup files from any source (e.g. Remote) to any target (usually the host, the script runs on). On completion (either successful or on error), the scripts sends a mail with the output of rsync to a specified mail address. 
 
 ## Dependencies
 sendmail needs to be installed and configured for sending backup notifications.
 
 ## Installation
-Pull the repository to a location of your choice on the host. 
-Configure your ssh client, such that rsync neither requires passwords, ports, etc. Use the ```config``` file under your ```.ssh``` folder. 
+Pull the repository to a location of your choice on the host.
+
+## Configuration 
+Configure your ssh client for all remote source or target directories specified in your configuration, 
+such that rsync neither requires passwords, ports, etc. Use the ```config``` file under your ```.ssh``` folder. 
+An example configuration for a host is given as follows. 
 ```
 Host sebastianvendt.de
         HostName sebastianvendt.de
@@ -14,16 +18,35 @@ Host sebastianvendt.de
         IdentityFile /home/sebastian/sshKeys/rsyncOnSebastianvendt.de.pem
 ```
 
+Create a configuration file, which holds the source and destination paths for the backup jobs as well as several configuration variables. 
+An example configuration file with all *required* variables is given in the following. 
+```
+#Backup directories
+declare -A backup_folders 
+backup_folders["backupuser@hostA.com:/opt/SourceFolderA"]="opt/backup/folderA"
+backup_folders["/opt/SourceFolderB"]="opt/backup/folderB"
+
+#Configuration
+logPath=/home/user/logs/backupjob/
+logFileName="$(date +'%Y-%m-%d_%H-%M')_backupjobs.log"
+tmpLogFilePath=/tmp/tmp_backup.log
+retryAttempts=2
+mailFrom="backup@backupserver.com"
+mailTo="user@domain.com"
+
+#Delete logs older than rotationDays
+rotationDays=14
+```
+
 ## How to run the script
-Create a configuration file, which holds the source and destination paths. An example configuration file is given in the following. Please note, this is also a shell script and it also must be executable!
+The script requires as argument the path to the configuration file 
 ```
-#!/bin/bash
-declare -A backup_folders #Do not change this name
-backup_folders["rsync@sebastianvendt.de:/var/lib/psa/dumps/domains/sebastianvendt.de/"]="/home/sebastian/ARCHIVE/sebastian/3000_BACKUP/sebastianvendt.de/configuration"
-backup_folders["backup@serles.local:/var/lib/openhab/backup"]="/home/sebastian/ARCHIVE/sebastian/3000_BACKUP/serles.local/backup"
+/path/of/script/getRemoteBackup.sh /path/to/configuration
 ```
 
-Add the script with the path to your configuration file to your crontab-file. I suggest to run it in a screen. You can then always reattach to the screen and check the current status for long backup jobs. 
+## Automate the backup job
+To automate your backup, add the script with the path to your configuration file to your crontab-file. I suggest to run it in a detached screen session. 
+You can then always reattach to the screen and check the current status for long backup jobs. 
 ```
 10 2 * * * sebastian screen -d -m /home/sebastian/scripts/backup/getRemoteBackup.sh /home/sebastian/scripts/backup/backupFolders.conf
 ```

+ 5 - 19
getRemoteBackup.sh

@@ -1,22 +1,9 @@
 #!/bin/bash
 
-#Read the backup folders from the config script outside the git repo
+#Read the backup folders and configuration variables from the config script
 . $1
-#Example script
-#declare -A backup_folders
-#backup_folders["/opt/SourceFolderA"]="opt/backup/folderA"
-#backup_folders["/opt/SourceFolderB"]="opt/backup/folderB"
 
-#Configuration
-logPath=/home/sebastian/ARCHIVE/sebastian/3000_BACKUP/
-logFileName="$(date +'%Y-%m-%d_%H-%M')_backupjobs.log"
-tmpLogFilePath=/tmp/tmp_backup.log
-retryAttempts=2
-
-#Delete logs older than rotationDays
-rotationDays=14
-
-#Variables
+#Local variables
 globalErrors=0
 logFilePath="${logPath}${logFileName}"
 
@@ -31,9 +18,8 @@ if pidof -o %PPID -x "$0" > /dev/null; then
 	exit
 fi
 
+#Run the backup jobs as defined in the backup_folders array from the config
 echo "Starting backup job(s)" | tee $tmpLogFilePath
-
-
 for sourceFolder in "${!backup_folders[@]}"
 do
 	mkdir -p ${backup_folders[$sourceFolder]}
@@ -69,10 +55,10 @@ find $logPath -type f -mtime +$rotationDays -name '*.log' -execdir rm -- '{}' \;
 #Mail Notifications
 if [ $globalErrors -eq 0 ]; then
 	#send mail for success
-	echo -e "To:mail@sebastianvendt.de\nFrom:Sebastian@manaslu.home\nSubject:Backup SUCCESSFUL on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail mail@sebastianvendt.de
+	echo -e "To:$mailTo\nFrom:$mailFrom\nSubject:Backup SUCCESSFUL on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail $mailTo
 else
 	#send mail for failure
-	echo -e "To:mail@sebastianvendt.de\nFrom:Sebastian@manaslu.home\nSubject:Backup FAILED on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail mail@sebastianvendt.de
+	echo -e "To:$mailTo\nFrom:$mailFrom\nSubject:Backup FAILED on $(date +'%c')\n\n$(cat $tmpLogFilePath)" | sendmail $mailTo
 fi
 
 #delete tmp file