• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Backup your MySQL databases over FTP

How VPS by How VPS
January 1, 2020
in Linux
0
0
SHARES
21
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Overview
  2. Description
  3. Crontab Sections
  4. Want to contribute?


Vultr offers automatic backup as an option for any Performance Series VPS. This article provides, in addition to this feature, an option to automatically create daily database backups on the server, and also send them over FTP to your backup server or even file hosts.

Overview
  • Automatic backups run daily. The time that the backup occurs is configurable.
  • Many file hosts offer file transfer over FTP, so you can automatically send your database to your personal account.
  • It sends an email after the backup is finished.

Description

First, create and change to the /backups directory.

 mkdir /backups
 cd /backups

Then, using nano or your favorite editor, create the script file:

nano backupdb.sh

Now, copy and paste this script, and edit the variables at the top according to your settings:

#!/bin/bash

############### Infos - Edit them accordingly  ########################

DATE=`date +%Y-%m-%d_%H%M`
LOCAL_BACKUP_DIR="/backups"
DB_NAME="database_name"
DB_USER="root"
DB_PASSWORD="root_password"

FTP_SERVER="111.111.111.111"
FTP_USERNAME="ftp-user"
FTP_PASSWORD="ftp-pass"
FTP_UPLOAD_DIR="/upload"

LOG_FILE=/backups/backup-DATE.log

############### Local Backup  ########################

mysqldump -u $DB_USER  -p$DB_PASSWORD $DB_NAME | gzip  > $LOCAL_BACKUP_DIR/$DATE-$DB_NAME.sql.gz

############### UPLOAD to FTP Server  ################

ftp -nv $FTP_SERVER << EndFTP
user "$FTP_USERNAME" "$FTP_PASSWORD"
binary
cd $FTP_UPLOAD_DIR
lcd $LOCAL_BACKUP_DIR
put "$DATE-$DB_NAME.sql.gz"
bye
EndFTP

############### Check and save log, also send an email  ################

if test $? = 0
then
    echo "Database Successfully Uploaded to the Ftp Server!"
    echo -e "Database Successfully created and uploaded to the FTP Server!" | mail -s "Backup from $DATE" [email protected]

else
    echo "Error in database Upload to Ftp Server" > $LOG_FILE
fi

After you have finished editing the script and have saved the file, we make the file executable by applying the following command:

 chmod +x backupdb.sh

You can test it now by typing in the terminal.

 /backups/backupdb.sh

… and after it finishes the execution, type ls -a to see if the database has been backed up. Also confirm if it was sent to your FTP server.

If everything worked well so far, we can make it run daily by using Crontab.

Crontab Sections

You can edit your crontab with the following command:

 crontab -e

This will bring up a text editor where you can input your schedule with each job on a new line.

Each of the sections is separated by a space, with the final section having one or more spaces in it. This is how a cron job is laid out:

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command

So, in the editor, type or paste this line:

 30 02 * * * /backups/backupdb.sh

The above example will run /backups/backupdb.sh at 02:30am on every day of every month. Of course, you can change the time as you prefer.

Now just save and close the file. At the time scheduled, the backup will be performed.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Upgrading to CustomBuild 2.0 With DirectAdmin

Next Post

Three Free Server Control Panels (Quick Install)

Next Post

Three Free Server Control Panels (Quick Install)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet