User Tools

Site Tools


interessen:computer:pc_technik:backup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
interessen:computer:pc_technik:backup [2015/01/30 13:23]
tomtom
interessen:computer:pc_technik:backup [2015/02/15 11:54] (current)
tomtom
Line 8: Line 8:
  
 Da ich das neue Script so flexibel wie möglich machen wollte habe ich mir überlegt, alle Parameter in ein extra File auszulagern. Ich habe wegen der einfachen Lesbarkeit -json als Format gewählt. Da ich das neue Script so flexibel wie möglich machen wollte habe ich mir überlegt, alle Parameter in ein extra File auszulagern. Ich habe wegen der einfachen Lesbarkeit -json als Format gewählt.
 +
 +===== Backup-Script =====
 +Es sind noch viele "echo" drinn damit man beim manuellen starten des Scriptes sehen kann, was gerade passiert und wie die folgenden Kommandos dann zusammen gesetzt werden.
  
   #!/bin/bash   #!/bin/bash
Line 53: Line 56:
   error_check()   error_check()
   {   {
-  IGNOR=`jq .error_hand.err_ignore $DATA_FILE|sed 's/\"//g'`+  echo "job 'error_check' is running" 
 +  IGNOR=`jq .jobs.error_check.err_ignore $DATA_FILE|sed 's/\"//g'`
   echo "error to ignor : "$IGNOR   echo "error to ignor : "$IGNOR
      
-  HIGH=`jq .error_hand.err_high $DATA_FILE|sed 's/\"//g'+  HIGH=`jq .jobs.error_check.err_high $DATA_FILE|sed 's/\"//g'
-  MEDIUM=`jq .error_hand.err_medium $DATA_FILE|sed 's/\"//g'+  MEDIUM=`jq .jobs.error_check.err_medium $DATA_FILE|sed 's/\"//g'
-  LOW=`jq .error_hand.err_low $DATA_FILE|sed 's/\"//g'`+  LOW=`jq .jobs.error_check.err_low $DATA_FILE|sed 's/\"//g'`
      
   for FILE in `cat $LOG_CHECK_FILE | grep '<f'|cut -d\/ -f2-`   for FILE in `cat $LOG_CHECK_FILE | grep '<f'|cut -d\/ -f2-`
Line 76: Line 80:
   fi   fi
   done   done
-  messaging 
   }   }
      
Line 115: Line 118:
   messaging()   messaging()
   {   {
-  echo "generate message for syslog"+  echo "job 'messaging' is running, generate massage for syslog"
   if [ $ERR_COUNT -gt 0 ]   if [ $ERR_COUNT -gt 0 ]
   then   then
Line 180: Line 183:
   echo $DIR   echo $DIR
   echo "run : "$METHOD `jq .jobs.replicate.run_options $DATA_FILE|sed 's/\"//g'` $DIR $DESTIN $PASS_OPT   echo "run : "$METHOD `jq .jobs.replicate.run_options $DATA_FILE|sed 's/\"//g'` $DIR $DESTIN $PASS_OPT
-  echo " " >> $LOG_FILE 
   echo "{"$DIR"()" >> $LOG_FILE   echo "{"$DIR"()" >> $LOG_FILE
   $METHOD `jq .jobs.replicate.run_options $DATA_FILE|sed 's/\"//g'` $DIR $DESTIN $PASS_OPT >> $LOG_FILE   $METHOD `jq .jobs.replicate.run_options $DATA_FILE|sed 's/\"//g'` $DIR $DESTIN $PASS_OPT >> $LOG_FILE
-  echo " " >> $LOG_CHECK_FILE 
   echo "{"$DIR"()" >> $LOG_CHECK_FILE   echo "{"$DIR"()" >> $LOG_CHECK_FILE
   $METHOD `jq .jobs.replicate.log_options $DATA_FILE|sed 's/\"//g'` $DIR $DESTIN $PASS_OPT >> $LOG_CHECK_FILE   $METHOD `jq .jobs.replicate.log_options $DATA_FILE|sed 's/\"//g'` $DIR $DESTIN $PASS_OPT >> $LOG_CHECK_FILE
Line 202: Line 203:
   {   {
   echo "job 'mount_fs' is running"   echo "job 'mount_fs' is running"
-        # check if target host available+  # check if target host available
   TARGET_SRV=`jq .jobs.mount_fs.ping_target $DATA_FILE|sed 's/\"//g'`   TARGET_SRV=`jq .jobs.mount_fs.ping_target $DATA_FILE|sed 's/\"//g'`
   echo "check, if you'r in right location, try to ping "$TARGET_SRV   echo "check, if you'r in right location, try to ping "$TARGET_SRV
   MOUNT_P=`jq .jobs.mount_fs.mount_point $DATA_FILE|sed 's/\"//g'`   MOUNT_P=`jq .jobs.mount_fs.mount_point $DATA_FILE|sed 's/\"//g'`
   if( ping -c 3  $TARGET_SRV > /dev/null )   if( ping -c 3  $TARGET_SRV > /dev/null )
-  then+  then
   echo $TARGET_SRV" reachable, you'r in right location to backup"   echo $TARGET_SRV" reachable, you'r in right location to backup"
   if [[ `jq .jobs.mount_fs.mount_def $DATA_FILE|sed 's/\"//g'` = "file" ]]   if [[ `jq .jobs.mount_fs.mount_def $DATA_FILE|sed 's/\"//g'` = "file" ]]
   then   then
   echo "mount "`jq .jobs.mount_fs.mount_opt $DATA_FILE|sed 's/\"//g'` `jq .jobs.mount_fs.mount_file $DATA_FILE|sed 's/\"//g'` $MOUNT_P   echo "mount "`jq .jobs.mount_fs.mount_opt $DATA_FILE|sed 's/\"//g'` `jq .jobs.mount_fs.mount_file $DATA_FILE|sed 's/\"//g'` $MOUNT_P
-          mount `jq .jobs.mount_fs.mount_opt $DATA_FILE|sed 's/\"//g'` `jq .jobs.mount_fs.mount_file $DATA_FILE|sed 's/\"//g'` $MOUNT_P+  mount `jq .jobs.mount_fs.mount_opt $DATA_FILE|sed 's/\"//g'` `jq .jobs.mount_fs.mount_file $DATA_FILE|sed 's/\"//g'` $MOUNT_P
   else   else
   CONNECT=`jq .jobs.mount_fs.mount_srv $DATA_FILE|sed 's/\"//g'`:`jq .jobs.mount_fs.mount_share $DATA_FILE|sed 's/\"//g'`   CONNECT=`jq .jobs.mount_fs.mount_srv $DATA_FILE|sed 's/\"//g'`:`jq .jobs.mount_fs.mount_share $DATA_FILE|sed 's/\"//g'`
Line 276: Line 277:
   logger $message   logger $message
   }   }
 +  
 +  # don't change sequence below
   setup   setup
   main   main
   exit   exit
  
 +===== Parameter-File =====
 +Das dazu gehörende ParameterFile sieht dann so aus bei mir:
 +
 +  {
 +  "description": "json-file to backup and restore per backup-script",
 +  "work_dir":"/data",
 +  "log_dir":"/data/backuplog",
 +  "log_remove":"yes",
 +  "job_seq":"mount_fs add_tasks.backup_opt replicate error_check messaging",
 +  "jobs":
 +  {
 +  "mount_fs":
 +  {
 +  "@":"'ping_target' is used to verify location; 'mount_def' can be 'file' or 'server'; in case of 'file', 'mount_file' needed",
 +  "ping_target":"192.168.2.1",
 +  "mount_def":"file",
 +  "mount_opt":"-t glusterfs",
 +  "mount_srv":"<file server>",
 +  "mount_share":"<file server share>",
 +  "@":"'mount_file' describe a method to connect to a server and his share(s), 'mount_srv' and 'mount_share' not needed in this case",
 +  "mount_file":"/etc/glusterfs/gluster1.vol",
 +  "mount_point":"/gluster"
 +  },
 +  "replicate":
 +  {
 +  "@":"'repli_opt' can be 'local' or 'remote', 'remote' needs 'pass_option', 'sync_server' and 'sync_user'",
 +  "repli_opt":"local",
 +  "@":"only rsync implemented yet, can try scp, but auth method must implemented by your self; use 'AX' to safe links",
 +  "method":"rsync",
 +     "run_options":"-avh -partial",
 +      "log_options":"-avhn -partial",
 +  "@":"pass_option : file content format 'username:password'",
 +  "pass_option":"--password-file=<file location>",
 +  "sync_server":"<rsyncd server>",
 +  "sync_user":"<username>",
 +  "@":"if absolute path used in 'sync_folders', not 'work_dir' needed",
 +  "sync_folders":"Carrier Closed Documentation Downloads notes privat Projekts Proposals transcripts backup transfer",
 +  "@":"'remote_folder' means the backup folder at the target file system",
 +  "remote_folder":"Arbeit"
 +  },
 +  "error_check":
 +  {
 +  "@":"'err_ignore' means witch files or search words can be ignore in error log or errors at backup this files are normal (i.e. log-files)",
 +  "err_ignore":"",
 +  "@":"error level definitions",
 +  "err_high":"",
 +  "err_medium":"notes",
 +  "err_low":""
 +  },
 +  "messaging":"<no further parameter needed, all included in backup script>",
 +  "add_tasks":
 +  {
 +  "<task name>":
 +  {
 +  "folder":"<target folder for task>",
 +  "task":"<can be external(!) script or command, no sub routine in backup script>"
 +  },
 +  "backup_db":
 +  {
 +  "folder":"mysql_backup",
 +  "task":"mysqldump -u root --password=<PASSWORD> --all-databases > $TARGET"
 +  },
 +  "backup_opt":
 +  {
 +  "folder":"backup",
 +  "task":"cp -r /opt/backup/*"
 +  }
 +  }
 +  }
 +  }
 +
 +
 +
 +Die Jobs "mount_fs" und "replicate" sind als feste Optionen, siehe "job_seq" (Job Sequence), fertig definierte Schritte im BackupScript. Wobei auch "mount_fs" nur eine Option ist. Ich habe bei mir "mount_fs" gewählt, damit ich bei der Replikation keine Authentifizierung benötige und auch gleichzeitig auf zwei verschiedene Platten, bei mir zwei Server, schreiben kann. Wenn also bei mir ein Server, wegen was auch immer, nicht zur Verfügung steht, dann kann ich trotzdem mein Backup machen.
  
 +"add_tasks" sind frei definierbare zusätzliche Aufgaben deren Auführungszeitpunkt in "job_seq" definiert wird.
interessen/computer/pc_technik/backup.1422620622.txt.gz · Last modified: 2015/01/30 13:23 by tomtom