Untitled

From Toxic Crane, 5 Months ago, written in Plain Text, viewed 1 times. This paste will go to its last resting place in 1 Second.
URL https://paste.ovh/view/4d8dd255 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2.  
  3. #Fileserver Backup Script
  4.  
  5. SSH_USER=
  6. SSH_PW=
  7. SSH_HOST=
  8.  
  9. #Installed needed tools
  10. for i in /usr/bin/lftp
  11. do
  12.         if [ -e $i ]
  13.         then
  14.                 echo "ok lftp found"
  15.         else
  16.                 apt -y install lftp
  17.         fi
  18. done
  19.  
  20. for e in /usr/bin/rsync
  21. do
  22.         if [ -e $e ]
  23.         then
  24.                 echo "ok rsync found"
  25.         else
  26.                 apt -y install rsync
  27.         fi
  28. done
  29.  
  30. for g in /usr/bin/sshpass
  31. do
  32.         if [ -e $g ]
  33.         then
  34.                 echo "ok sshpass found"
  35.         else
  36.                 apt -y install sshpass
  37.         fi
  38. done
  39.  
  40. #Workround
  41. mkdir -p /home/MYSQL-BACKUPS/public_html
  42.  
  43. for D in $(find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d) ; do
  44.     echo ${D##*/}
  45.     mysqldump -u root ${D##*/} > /home/MYSQL-BACKUPS/${D##*/}.sql
  46.     gzip /home/MYSQL-BACKUPS/${D##*/}.sql
  47.     echo '';
  48. done
  49.  
  50. rm /home/MYSQL-BACKUPS/modsec.sql -f
  51.  
  52. #Yesterdays date in ISO-8601 format:
  53. DAY1=`date -d "yesterday 13:00" '+%Y-%m-%d'`
  54.  
  55. #Todays date in ISO-8601 format:
  56. DAY0=`date -I`
  57.  
  58. lftp sftp://${SSH_USER}:${SSH_PW}@${SSH_HOST}  -e "mkdir -p media/host/backup__$DAY0/home/MYSQL-BACKUPS; bye"
  59.  
  60. /usr/bin/sshpass -p "$SSH_PW" /usr/bin/rsync -avhi -e 'ssh -o StrictHostKeyChecking=no -p 23' --link-dest /home/MYSQL-BACKUPS/ /home/MYSQL-BACKUPS/ "$SSH_USER"@$SSH_HOST:media/host/backup__$DAY0/home/MYSQL-BACKUPS/
  61.  
  62. for F in $(find /home/ -mindepth 1 -maxdepth 1 -type d) ; do
  63.  
  64.     echo $F
  65.  
  66.     lftp sftp://${SSH_USER}:${SSH_PW}@${SSH_HOST}  -e "mkdir -p media/host/backup/home_backup__$DAY0$F; bye"
  67.  
  68.     #The source directory:
  69.     SRC="$F/public_html/"
  70.  
  71.     #The target directory:
  72.     TRG="[email protected]$SSH_HOST:media/host/backup/home_backup__$DAY0$F/"
  73.  
  74.     #The link destination directory:
  75.     LNK="$SRC"
  76.  
  77.     echo /usr/bin/sshpass -p "$SSH_PW" /usr/bin/rsync -avhi $LNK -e 'ssh -o StrictHostKeyChecking=no -p 23' --link-dest $LNK $SRC $TRG
  78.     /usr/bin/sshpass -p "$SSH_PW" /usr/bin/rsync -avhi -e 'ssh -o StrictHostKeyChecking=no -p 23' --link-dest $LNK $SRC "$SSH_USER"@"$SSH_HOST:media/host/backup/home_backup__$DAY0$F/"
  79. done

Reply to "Untitled"

Here you can reply to the paste above

captcha