Menu Show

MySQL Backup Script for Quick MySQL Backup in Linux/Windows

Rate this article: 1 Star2 Stars3 Stars4 Stars5 Stars (10 votes, average: 4.70)
Loading...

Here’s how you can enable automatic backups on your web server using MySQL backup script and tool

With weird clothes and geeky spectacles, website administrators look like different animals compared to us. And in many ways, they are. But there’s one thing in common between us and them, and that’s the constant fear of losing all  your data and information. Just like we’re afraid of losing all our data from our devices, website administrators are afraid of losing all the data from their web servers. This fear rises with each upload and change made to the data structure. That’s why, backing up data regularly has become a routine for many. If you’re a website administrator, this article will give you MySQL backup script for quick MySQL backup in Linux as well as in Windows. With this script, you won’t need to download any MySQL backup tool.

Let’s get started!

Create MySQL Auto Backups in Windows Server Using MySQL Backup Script in 9 Easy Steps

If you want to use a MySQL backup script to backup your Windows server data, then you must follow the steps listed below. Don’t worry, it’s going to be quite easy. 9 steps are all it takes! Ready to get going?

  • First, open Notepad and save the following MySQL backup script.

Note: You must specify the SET parameters and the mysqldump.exe location as per your configuration.

@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)

SET backupdir=C:\xampp\htdocs\backup
SET mysqluername=root
SET mysqlpassword=somepassword
SET database=dbname

C:\xampp\mysql\bin\mysqldump.exe -uroot -pPASSWORD %database% > %backupdir%\%database%_%mydate%_%mytime%_.sql
  • Now go to Start > All Programs > Accessories > Command Prompt to open Command Prompt.
  • In the Command Prompt, type Taskschd.msc.
  • Choose the Create Task… option that’s under Actions pane on the right-hand side of the screen.
  • Select the user that has all the admin rights.
  • Now click Run whether user is logged on or not and Run with highest privileges.
  • Click on the Triggers tab at the top of the screen.
  • Finally, in the Actions tab, choose the batch file that we created in the first step.
  • Click OK.

Voila! The MySQL backup script has just enabled auto backup on your Windows server. Simple, right?

Create MySQL Auto Backups in Linux/Ubuntu Using MySQL Backup Script

The process of MySQL auto backups in Linux/Ubuntu can be mainly divided into two steps. The first is using the mysqldump command and the second is automating the backup process. Let’s perform both steps to get your automatic backups in place.

Step 1: Use the mysqldump Command

A great thing about mysqldump command is that we don’t need to use any external MySQL backup tool for backing up the data. Here’s the mysqldump that you need to use:

$ mysqldump -u username -p database_name > backup_file_name.sql

Note: You must change the username, database_name and backup_file_name to the correct details. You should also enter your database password if prompted to do so.

Step 2: Automate the Backup Process

In order to set up automatic backups, you must download a MySQL backup tool/utility provided by Ubuntu. With this tool at your disposal, you don’t need to run backups manually.

Enter the following command to download the tool:

$ sudo apt-get install automysqlbackup

Then run the command below to take on-demand backups:

$ sudo automysqlbackup

Finally, use the following command to specify the content of the scheduled MySQL backups:

$ sudo ls -a /var/lib/automysqlbackup/daily

Congratulations! You’ve just enabled automatic MySQL backups on your Linux/Ubunty web server. Fun, wasn’t it?

CodeGuard: A Silver Bullet to All Your Backup Management Headaches

No matter how frequently we take backups, there comes a time when we lose some crucial data. That’s because the conventional system of taking backups is done by us, and we have many limitations. What if you could give all your backup management troubles to a tool that not only takes backups, but also secures it against security attacks.

We’re talking about CodeGuard backup platform by Sectigo (formerly known as ‘Comodo’). Whether you’re looking to backup websites, MySQL database, FTP/SFTP/FTPS file backup, CodeGuard has got you covered. It allows you to perform one-click on-demand backups and schedule automatic backups as well. CodeGuard encrypts the backed up data using 256-bit AES encryption and protects the databases against malware through its MalwareGone scanner. So, if you’re looking for a data backup tool that gives you peace about your backup worries and costs less than a Starbucks coffee, then CodeGuard is the solution for you.

<div class="graysection">
<h2>Get CodeGuard at $1.63/Month Only! Buy it Today and Save Up to 50% With SectigoStore!</h2>
<p>Its More than Just a Backup Tool! Get Free Malware Removal, Free AWS Storage Space, One-Click Restoration and Strong 256-bit AES encryption of Backup Files with CodeGuard!  </p>
<a class="greenbutton" style="text-decoration: none;" href="https://sectigostore.com/codeguard/backup">Shop Now</a>
</div>

Code Signing Certificates

Get CodeGuard at $1.63/Month Only! Save Up to 50% With ComodoSSLstore!

CodeGuard comes with amazing features like daily Automatic Backups, One-Click Restore, Malware Scanning, and Advanced 256-bit AES encryption.
Shop CodeGuard Backup Solution