Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # get the content of the $1 file, and uses it to extract bases to backup.
  4. # a server begins with servername
  5. # then, a relative list of bases to save, with user and passes : base user pass
  6. # server ends with a blankline
  7.  
  8. todo=$1
  9. blankline="true"
  10. basedir=/media/backup/bases
  11.  
  12.  
  13. backit() {
  14. ssh backup-us@$server "mysqldump -u$user -p$pass $instruct | gzip" > $basedir/$instruct/$(date +%Y-%m-%d).gz
  15. }
  16.  
  17. cat $todo | while read instruct
  18. do
  19.     echo instruct = $instruct
  20.     if [ "$instruct" != "" ]
  21.     then
  22.         echo instruct != ""
  23.         if [ "$blankline" == "false" ]
  24.         then
  25.             echo base = $instruct
  26.             mkdir -p $basedir/$instruct
  27.             echo $(backit)
  28.         fi
  29.  
  30.         if [ "$blankline" == "true" ]
  31.         then
  32.             i=0
  33.             for val in $instruct
  34.             do
  35.                 if [ "$i" -eq "0" ]
  36.                 then
  37.                     server=$val
  38.                 elif [ "$i" -eq "1" ]
  39.                 then
  40.                     user=$val
  41.                 elif [ "$i" -eq "2" ]
  42.                 then
  43.                     pass=$val
  44.                 fi
  45.                 i=$(( $i + 1 ))
  46.             done
  47.             echo conninfos = $server $base $user $pass
  48.             blankline="false"
  49.         fi
  50.     fi
  51.    
  52.     if [[ "$instruct" == "" ]]
  53.     then
  54.         blankline="true"
  55.     fi
  56.  
  57. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement