The following sql code takes backup of all MSSQL databases to “D:\database\”, and all these backup files will be having a “*.BAK” extension. Save this file as “D:\database\Backup.sql”.
Note down the system name(from msinfo32). In my case the system name was “WINDOWS”, replace this with your system name 😉 . Save the following code as a batch file named “D:\database\ftpbackup.bat”. The script will upload all these database backup to a directory named “backup/windows1_bd” in the remote ftp server.
In this article i will explain how to take cpanel backup to amazon s3(with backup rotation enabled). The step by step procedure is explained below,
Step1) Activate an account in s3. You will get an access key and secret_key after the activation.
You can create a new s3 account by following the url,
Step2) Install s3 client for linux. The package name is “s3cmd-1.0.0-4.1”.
On redhat or centos based machines(using rpm packages), you can install “s3cmd” as follows,
Alternatively, you can download it from the url pasted below:
Step3) Configure s3 client using the command,
It will ask for the access key and secret key that we got during our account activation. This process reports failure, if we provide the wrong key values. Once this step is completed, the configuration will be stored inside the file “/root/.s3cfg”.
During configuration you will be asked whether to enable encryption or not. Enabling encryption will improve the security of transfer but will make the upload a little bit slower.
Step4) We need to create buckets in s3 for storing the backup.
eg: creating a bucket named “Backup_daily”,
For additional options refer the url,
Step5) Enable daily backup from WHM. Refer the url pasted below for reference,
If backup is already configured, then we can know the location of the backup using the command,
Inside “/backup” there will be another directory named “cpbackup”, which will be holding the daily,weekly and monthly backup’s. In my case,
Step6) Create log directories,
Step7) Write a script to automate the backup, and save it as “/root/dailybackup.sh” . In the script pasted below, the backup rotation degree is set as 3(“DEGREE=3” , line16). This means that, 3 days old backup will be deleted automatically. You can increase this backup retention period by adjusting the “DEGREE” variable in line16.
Step8) Grant execute privilege for the script and schedule it to run everyday,
Or if you wish to start the amazon s3 backup script right after the cpanel backup process, then create a cpanel post backup hook named “/scripts/postcpbackup” with the following contents,
The post backup hook will start the amazon s3 backup script right after every cpanel backup completion.
In case of disasters we can download the backup from the bucket using the same s3cmd tool.