Running Auto Backups

From HelioHost Wiki
Jump to: navigation, search

Contents

Introduction

This article will guide you for the following:

  • Optional (only if you have Softaculous installations): Setting Softaculous Automatic Backups to be stored in your Google Drive/Dropbox account/FTP
  • Coding a executable backup system through them Linux Shell
  • Optional: Mailing The Backup Automatically To An Email ID
  • Setting Up Cron To Run It Automatically as per schedule

Automatic Remote Softaculous Backups (Google Drive/Dropbox/FTP)

Note: Skip this paragraph if you don't have Softaculous installations, and proceed with Stage 1.

If you want to backup your Softaculous installations to a remote server, follow these guides written by Softaculous developers:

Stage 1: Coding the shell file

You can use any usual text editor like Notepad for Windows to write this file.


Start the file with bash command:

#!/bin/bash


Create the MySQL dump:

/bin/mysqldump --user=cpUsername --password=cpPassword cpUsername_database > /home/cpUsername/cpUsername_database.sql


Remove the old backups:

rm -f /home/cpUsername/backup.tar.gz


Archive and Compress your SQL Dump and public_html folder:

cd /home/cpUsername/

/bin/tar zxvf /home/cpUsername/backup.tar.gz *.sql public_html/*


Note: If you want to add a folder outside public_html, you can enter folder_name/*.


Note: Replace cpUsername and cpPassword with you respective cPanel username and password. Replace database with your database name. Repeat this line for every database you have. Also replace Email ID with the required email which will receive the backup.


Optional Step: Attaching and Mailing:

date | /bin/mutt -a "/home/cpUsername/backup.tar.gz" -s "cPanel Automated Backup" -- Email ID

BEWARE: The backup is not encrypted. Mailing it to an unknown Email will give the Email ID Owner access to all MySQL databases and public_html folder. any credentials contained within will be exposed.


Save the file as a .sh file with the name backup. So the file will be backup.sh. It is a linux shell file and cannot be executed on a windows/mac.

Upload it to the root directory of your account i.e. /home/cpUsername/

Give it 755 permissions. It cannot run without these required permissions. The permissions can be modified using the cPanel's inbuilt File Manager.

Stage 1 Done!!!


Stage 2: Setting the cron

In your cPanel, go to Cron Jobs under Advanced Section in any theme.

Set it to run monthly and then change the minute, hour and day of the operation to something random.

Request: please do not run it more frequently than monthly and set the day, minute and hour of run to something completely random to prevent a collective load on the server. If everyone runs their backup at the same time, it will cause a very heavy load on the server and all of us love HelioHost, so please. This is a sincere request from a HelioHost user to other users.

In the command box type:

/home/cpUsername/backup.sh

If you want to prevent error messages from being emailed you can add "2>/dev/null" to the end of the command. An error message will always be created as you will be passing a password on the linux shell command line.

Stage 2 Done!!!


This is the end. Your automatic backup system is ready.

An Assembled Example

#!/bin/bash

/bin/mysqldump --user=user123 --password=test123 user123_testdb > /home/user123/user123_testdb.sql

rm -f /home/user123/backup.tar.gz

cd /home/user123/
/bin/tar zxvf /home/user123/backup.tar.gz *.sql public_html/*

date | /bin/mutt -a "/home/user123/backup.tar.gz" -s "cPanel Automated Backup" -- user123@example.com
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Google AdSense