download-backup-http 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. #/###################################################################\
  3. #| Download backup's from backup.castanedo.es |
  4. #| Download all files in a http/https repository with Auth Basic |
  5. #| authentication. |
  6. #| Help: |
  7. #| -$scheme: protocol (http, https, ftp, ...) |
  8. #| -$url: url without $scheme of the repository. |
  9. #| Ex: backup.example.com/some/where |
  10. #| -$httpuser: user for Auth Basic Auth. |
  11. #| -$httppass: password for Auth Basic Auth. |
  12. #| -$backupDir: directory to save repository files. |
  13. #| |
  14. #| Guzmán Castanedo (guzman@castanedo.es) |
  15. #| March 2017 |
  16. #| Licence: GPL v3.0 -> https://www.gnu.org/licenses/gpl-3.0.en.html |
  17. #\###################################################################/
  18. scheme="https://"
  19. url="backup.castanedo.es"
  20. httpuser="authbasicuser"
  21. httppass="authbasicpasswd"
  22. backupDir=/home/$USER/Documentos/backup
  23. #Check directory and remove index.html (or didn't upgrade)
  24. if [ ! -d $backupDir/$url ];then
  25. mkdir -p $backupDir/$url
  26. if [ $? != 0 ];then
  27. printf "ERROR: Imposible crear %s\n" $backupDir/$url
  28. exit 1
  29. fi
  30. fi
  31. if [ -f $backupDir/$url/index.html ];then
  32. rm $backupDir/$url/index.html
  33. if [ $? != 0 ];then
  34. printf "ERROR: Imposible borrar %s\n" $backupDir/$url/index.html
  35. exit 1
  36. fi
  37. fi
  38. #Download with wget
  39. printf "Destino backups:\t%s\n" $backupDir
  40. printf "Sincronizando backup's desde %s\n" $scheme$url
  41. wget -q --tries=3 -r -c --user=$httpuser --password=$httppass --directory-prefix=$backupDir $scheme$url
  42. if [ $? != 0 ];then
  43. printf "ERROR: Se han producido errores en la sincronizacion\n"
  44. exit 1
  45. fi
  46. printf "Descarga correcta :)\n"