Quantcast
Channel: YourHowTo.net » WHM/cPanel
Viewing all articles
Browse latest Browse all 13

File backup script using cronjob

$
0
0
backup folder

File backup script using cronjob

Just before the New Years a visitor was inquiring about how can he backup his account files, not just to backup the mysql databases. Well the process itself is similar, not that hard really. You do however need to understand that you should have access to the zip or tar binaries to be able to create the archive. Normally this is alright on cPanel where these are present.

The script itself can be used on any different linux operating system, not just with cPanel. Anyway, lets get this started.

The script …

The script is simple, consist of a few lines of code and we will save it in a file we name “file_backup.sh”

#!/bin/bash

date=`date +"%Y-%m-%d"`;
/usr/bin/zip -9 -r /home/username/backups/filebackup_$date.zip /home/username/folder_to_backup

  • the date line will save in a variable the current date of the execution
  • the last line will be the zip command to create the archive
  • username – this is the cpanel account username

Don’t forget that the backups folder needs to be created or you will receive errors.

What this does, it creates a zip archive “filebackup_$date.zip” in the location “/home/username/backups/”.

The last part is actually what you want to add to your zip archive. You can add directly a folder and will recursively add everything in it.

Creating a backup cronjob

The cronjob command it would look similar to bellow:

0,30 * * * * /bin/sh /home/username/file_backup.sh

I have bellow a screenshot of the previous cronjob backup I made, this is similar, you just need to use the correct name of the file, which is “file_backup.sh”

Comanda Cronjob cPanel

Also don’t forget the fact that this backup script will create each day a backup. You may want to run the backup only on specific dates if you are concern of the disk space or delete the old backup files that are generated.

That’s all, if you have any problems or you believe there’s anything else that you want me to write about, feel free to contact me.

The post File backup script using cronjob appeared first on YourHowTo.net.


Viewing all articles
Browse latest Browse all 13

Latest Images

Trending Articles





Latest Images