File backup script using cronjob

→ Are you a new visitor? Please visit the page guidance for new visitors ←

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 “”

  • 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_$” 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:

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 “”

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.

Request an article ←