12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/bin/bash
- host="backup.castanedo.es"
- sftpuser="sftpuser"
- sftppass="sftppass"
- sftpkey=""
- remotefile=/var/www/*.html
- backupDir=/home/$USER/Documentos/backup
- if [ ! -x $(which ssh) ];then
- printf "ERROR:\tssh client Not Installed :O"
- exit 1
- fi
- if [ ! -x $(which sshpass) ];then
- printf "ERROR:\tsshpass Not Installed :O\n"
- exit 1
- fi
- if [ ! -d $backupDir/$host ];then
- mkdir -p $backupDir/$host
- if [ $? != 0 ];then
- printf "ERROR: Imposible crear %s\n" $backupDir/$host
- exit 1
- fi
- fi
- printf "Destino backups:\t%s\n" $backupDir/$host
- cd $backupDir/$host
- echo "Sincronizando backup's desde sftp://$sftpuser@$host:$remotefile"
- if [ ! -f $sftpkey ] || [ -z $sftpkey ];then
-
- export SSHPASS=$sftppass
- sshpass -e sftp -oBatchMode=no -a $sftpuser@$host:$remotefile
- if [ $? != 0 ];then
- printf "ERROR:\tSe han producido errores en la sincronizacion\n"
- exit 1
- fi
- else
-
- export SSHPASS=$sftppass
- sshpass -e sftp -oBatchMode=no -a -i $sftpkey $sftpuser@$host:$remotefile
- if [ $? != 0 ];then
- printf "ERROR:\tSe han producido errores en la sincronizacion\n"
- exit 1
- fi
- fi
- printf "Descarga correcta :)\n"
|