Skip to main content

Access denied for user in backup

Comments

4 comments

  • vanessa
    URL is broken - please attach script
    0
  • behinam
    0
  • behinam
    URL is broken - please attach script

    #!/bin/bash #################################################### # FTP backup script. # #################################################### #Backup all databases except the followings: #information_schema and performance_schema and mysql # #Database location, hostname or IP address. (If using the hostname DO NOT forget to define it in /etc/hosts file) DB_HOST="localhost" ################################# #Fill FTP credentials. If you only have one FTP server, leave one of the following parameters block blank. # #FTP1 FTP1HOSTNAME='yourAddress' FTP1USERNAME='user' FTP1PASSWORD='password' #FTP2 FTP2HOSTNAME='' FTP2USERNAME='' FTP2PASSWORD='' ################################ #Enable or Disable FTP transfer. FTP1_TRANSFER=yes FTP2_TRANSFER=no ############################################################################################### #To delete the backup folder -which is $ROOTPATH- enable the following parameter.(values:yes/no) # DeleteAfterTransfer=yes ################################################################### #Cheking whether the system has DirectAdmin or Cpanel control panel # DAP="/usr/local/directadmin/conf/mysql.conf" CPP="/root/.my.cnf" if [ -f $DAP ] then SYSTEM="Directadmin"; elif [ -f $CPP ] then SYSTEM="Cpanel"; else echo "No Control Panel Detected"; exit; fi echo "$(date "+%Y/%d/%m %H:%M:%S"): System Control Panel is: $SYSTEM." >> $ROOTPATH/dump_log; DATE=$(date "+%Y_%d_%m") ROOTPATH=/home/backup/databases ##Check whether the destination exists or not if [ ! -d "$ROOTPATH" ]; then mkdir -p $ROOTPATH echo "$(date "+%Y/%d/%m %H:%M:%S"): $ROOTPATH Folder is Created." >> $ROOTPATH/dump_log; else echo "$(date "+%Y/%d/%m %H:%M:%S"): $ROOTPATH Folder Exists." >> $ROOTPATH/dump_log; fi CHECK_MYSQL_AVAILABILITY=$(mysqladmin -h $DB_HOST -u $DBUSER -p $DBPASSWORD ping 2>>$ROOTPATH/dump_log|wc -l); if [ $CHECK_MYSQL_AVAILABILITY = '1' ] then echo "$(date "+%Y/%d/%m %H:%M:%S"): Successfully Connected to MySql Server" >> $ROOTPATH/dump_log; echo "$(date "+%Y/%d/%m %H:%M:%S"): Backup Process Started." >> $ROOTPATH/dump_log; cd $ROOTPATH mkdir backup_$DATE cd backup_$DATE mysql -h $DB_HOST -u $DBUSER -p $DBPASSWORD -e 'show databases'|egrep -v '(Database|performance_schema|information_schema|mysql)'|\ while read dbname; do echo "$(date "+%Y/%d/%m %H:%M:%S"): Backup $dbname Started." >> $ROOTPATH/dump_log; mysqldump -h $DB_HOST -u $DBUSER -p $DBPASSWORD $dbname 2>>$ROOTPATH/dump_log |gzip > $dbname.sql.gz echo "$(date "+%Y/%d/%m %H:%M:%S"): Backup $dbname Finished." >> $ROOTPATH/dump_log; done; else echo "$(date "+%Y/%d/%m %H:%M:%S"): Backup process has been finished with errors. Check $ROOTPATH/dump_log for more info."; exit fi echo "$(date "+%Y/%d/%m %H:%M:%S"): Backup Process Has been Finished Successfully" >> $ROOTPATH/dump_log; ###################################################### #Transfer Backup files Over FTP to FTP1 # if [ $FTP1_TRANSFER = 'no' ] then exit; fi echo "$(date "+%Y/%d/%m %H:%M:%S"): FTP1 Transfer to FTP1 Has been Started" >> $ROOTPATH/dump_log; ftp -n -v $FTP1HOSTNAME << EOT user $FTP1USERNAME $FTP1PASSWORD prompt binary cd sql2/ mput * bye EOT echo "$(date "+%Y/%d/%m %H:%M:%S"): FTP1 Transfer to FTP1 Has been Completed" >> $ROOTPATH/dump_log; if [ $DeleteAfterTransfer = 'yes' ] then cd .. rm -rf backup_$DATE; echo "$(date "+%Y/%d/%m %H:%M:%S"): Backup Folder backup_$DATE Has been Deleted Successfully" >> $ROOTPATH/dump_log; fi ####################################################### #Transfer Backup files Over FTP to FTP2 backup storage # if [ $FTP2_TRANSFER = 'no' ] then exit; fi echo "$(date "+%Y/%d/%m %H:%M:%S"): FTP2 Transfer to FTP2 Has been Started" >> $ROOTPATH/dump_log; ftp -n -v $FTP2HOSTNAME << EOT user $FTP2USERNAME $FTP2PASSWORD prompt binary cd backupdb mput * bye EOT echo "$(date "+%Y/%d/%m %H:%M:%S"): FTP2 Transfer to FTP2 Has been Completed" >> $ROOTPATH/dump_log;
    0
  • vanessa
    This is the command causing a problem, I believe mysqldump -h $DB_HOST -u $DBUSER -p $DBPASSWORD $dbname 2>>$ROOTPATH/dump_log |gzip > $dbname.sql.gz
    Are you able to execute this on the command line of your Ubuntu server, replacing those variables?
    0

Please sign in to leave a comment.