Jump to content

Automated Database Backup


bear

Recommended Posts

I have a problem with uuencode. The script freezes at uuencoding. I tried to manually run 'uuencode file.tar.gz > file.tar.gz.uu' and it just freezes. If I try 'uuencode file.tar.gz' then it successfully dumps to stdout. What could be the problem? Thank you.

Link to comment
Share on other sites

  • 1 month later...

Here is how to run mysqldump on Windows.

I got this little script from somewhere on the net and modified it to run on windows.

All you need to do is download the free exe gzip.exe (A search on google will find that)

Set your paths/user/passwords.

 

Save the following script as say backup.bat and use windows scheduler to run it daily hourly or whatever you want.

 

Please note: While this works fine for us and has been for years it may not be for every one. Usual disclaimer: Its here for you to use as IS.

 

//--- Begin Batch File ---//

@echo off

 

:: Set some variables

set bkupdir=c:\foldername or \\servername\sharename

set mysqldir=c:\mysql

set datadir=c:\mysql\data

set logdir=c:\mysql\logs

set dbuser=dbusername

set dbpass=dbpassword

set zip=c:\GZip\gzip.exe

set endtime=0

 

:GETTIME

 

:: get the date and then parse it into variables

for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (

set mm=%%i

set dd=%%j

set yy=%%k

)

 

:: get the time and then parse it into variables

for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do (

set hh=%%i

set ii=%%j

set ss=%%k

)

 

:: If this is the second time through then go to the end of the file

if "%endtime%"=="1" goto END

 

:: Create the filename suffix

set fn=_%yy%%mm%%dd%_%hh%%mm%%ss%

 

:: Switch to the data directory to enumerate the folders

pushd %datadir%

 

:: Write to the log file

echo Beginning MySQLDump Process > %logdir%\LOG%fn%.txt

echo Start Time = %yy%-%mm%-%dd% %hh%:%ii%:%ss% >> %logdir%\LOG%fn%.txt

echo --------------------------- >> %logdir%\LOG%fn%.txt

echo. >> %logdir%\LOG%fn%.txt

 

:: Loop through the data structure in the data dir to get the database names

for /d %%f in (*) do (

 

:: Create the backup sub-directory is it does not exist

if not exist %bkupdir%\%%f\ (

echo Making Directory %%f

echo Making Directory %%f >> %logdir%\LOG%fn%.txt

mkdir %bkupdir%\%%f

) else (

echo Directory %%f Exists

echo Directory %%f Exists >> %logdir%\LOG%fn%.txt

)

 

:: Run mysqldump on each database and compress the data by piping through gZip

echo Backing up database %%f%fn%.sql.gz

echo Backing up database %%f%fn%.sql.gz >> %logdir%\LOG%fn%.txt

%mysqldir%\bin\mysqldump --user=%dbuser% --password=%dbpass% --databases %%f --opt --quote-names --allow-keywords --complete-insert | %zip% > %bkupdir%\%%f\%%f%fn%.sql.gz

echo Done...

echo Done... >> %logdir%\LOG%fn%.txt

)

 

:: Go back and get the end time for the script

set endtime=1

goto :GETTIME

 

:END

:: Write to the log file

echo. >> %logdir%\LOG%fn%.txt

echo --------------------------- >> %logdir%\LOG%fn%.txt

echo MySQLDump Process Finished >> %logdir%\LOG%fn%.txt

echo End Time = %yy%-%mm%-%dd% %hh%:%ii%:%ss% >> %logdir%\LOG%fn%.txt

echo. >> %logdir%\LOG%fn%.txt

 

:: Return to the scripts dir

popd

 

:: Send the log file in an e-mail

REM c:\commail\commail -host=smtp.yourcompany.com -from="server <server@yourcompany.com>" -to=serveradmins@yourcompany.com -subject="MySQL Backup" -msg=%logdir%\LOG%fn%.txt

 

//--- End Batch File ---//

 

NOTE: Don't use the email send section unless you know how to, I was never able to get this to work.

Script will create a separate folder for each DB on the server for each backup.

 

Regards

Dave

Link to comment
Share on other sites

  • 1 month later...
when sent to a yahoo email, i receive only a text:

"begin 644 /home/username/mydbs/22-username_db.sql.gz

`

end"

 

the same email sent to the server's email address has a .gz archive attached which seems to be corrupt, i can;t manage to open it.

 

same problem here. can someone pelase help? the FTP is fine. but the Email seems to be stuck.

Link to comment
Share on other sites

  • 2 weeks later...

found it!

 

As for record function:

 

The database is where all your WHMCS data is stored and so is very important. It is therefore recomended that you take regular backups of it. There are 2 built in solutions for automated backing up the database using the daily cron - one is email and the other is an FTP backup to a remote server. These can be configured in Configuration > Database Backups.

 

You can also download a one off backup with the steps below.

 

1. Go to Utilities > Database Status

2. Click the Download Full Database Backup button at the top of the page

3. You should be prompted for a file to download. Save the file to your computer. Depending on the database size, this may take a few moments.

4. Once the download is complete you have now backed up your database.

Link to comment
Share on other sites

ummm having this script as 755 means it is rwxr-xr-x .. meaning other users on the system can read it and get the db username and password? Is that safe for a database that holds private user information and accounts, allowing others to change it?

 

or am I missing something here ..

Link to comment
Share on other sites

ummm having this script as 755 means it is rwxr-xr-x .. meaning other users on the system can read it and get the db username and password? Is that safe for a database that holds private user information and accounts, allowing others to change it?

 

or am I missing something here ..

 

If you mean the script I posted, you don't place it within the publicly accesible areas of your hosting account. That, in combination with not allowing cross account directory browsing, you should be fine.

Link to comment
Share on other sites

  • 2 years later...
  • 1 month later...
Even though I have put my email there and run the cron without any errors the DB backup does not coming to my email. Any ideas?

 

I have the very same problem. I've re-installed and cannot work out why I'm not getting the backups via email.

 

Any suggestions welcome..

Link to comment
Share on other sites

  • 2 months later...

Database Backups

 

According to the instructions.

 

There are 2 built in solutions for backing up the database using the daily cron - one is email and the other is an FTP backup to a remote server.

 

I want to use the email option.

 

Daily Email Backups

Then you enter your email address and select "Save Changes"

 

Nothing arrives.

Where is the daily cron located?

Link to comment
Share on other sites

You should have created the daily cron when WHMCS was installed. Review Utilities > Activity Log for any entries beginning "Cron Job".

 

Thanks for your reply.

 

I have checked that area and there's no mention of an MySQL Backup Cron Job being performed at all.

 

There is also a cron job setup in our CPanel and running every night which calls the admin/cron.php.

Link to comment
Share on other sites

Thanks for your reply.

 

I have checked that area and there's no mention of an MySQL Backup Cron Job being performed at all.

 

There is also a cron job setup in our CPanel and running every night which calls the admin/cron.php.

 

I can't belive it.

 

For some reason I have now got my first WHMCS database backup in a very long while.

I have not changed anything since my last couple of posts.

 

Some thing must have changed thou..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated