Backup your system using a simple Shell Scripts

by Sidick Allaladé on 13/02/2020

Updated at 1/02/2023

This is a super simple way to backup your system without spending a penny. It can be really practical, as backup is always important.

Someone said "When your data does not exist 3 times, that means it's not exist at all". So made some backup and backup your backup :smile::smile:

Here we go:


date echo "############### Backup of files on my server ###############"

backupfilename=server_backup_`date '+%Y-%m-%d'`

echo "----- Sql first and dumping current DB -----" rm -f /tmp/backup.sql mysqldump --user=youruser --password=yourpassword --all-databases --add-drop-table > /tmp/backup.sql

echo "----- Tar plus zip all files -----"

tar cvf /home/mybackups/files/${backupfilename}.tar /home/www/html/* /tmp/backup.sql gzip /home/mybackups/files/${backupfilename}.tar chmod 666 /home/mybackups/files/${backupfilename}.tar.gz echo "############### Backup done successfully.... ###############" date


Now let explain each line:

  • date => we want to see the server date in our log file
  • backupfilename=server_backup_`date '+%Y-%m-%d'` => filename of the backup with date
  • rm -f /tmp/backup.sql ==> we are removing the old sql backup file generated
  • mysqldump => we are backing up all the sql DB again
  • tar cvf home/www/html/ /tmp/backup.sql => You are backing up all home/www/html/* and /tmp/backup.sql You can also exclude some paths there with : --exclude='yourpathfile'

Oshara CEO Sidick

Find Out How My Team will "transform" your businesses through Reliable Application or Technology

Web development - We are a team of passionate web coders that will materialize your ideas in ways you could not even imagine.

API Integration - There is no secret using any API, connect all the tools you need, the way you need it.

IT And Cybersecurity Audit - Protect your customers, protect your business and protect yourself.

Maintenance & Support - We help organization to increase efficiency, improve performance, minimize downtime, and extend their lifespan.

Book a Call

NOW let's Executing the Script

Name your file ''
To execute it you need to opne terminal prompt and start with a dot '.' so if you name your file you will do
Now let's automate it because you probably don't want to do it manually everyday.
So if you want to auto run it everyday at 23h55 you will open your crontab with crontab -e and you will add this :

55 23 * * * /path/toyourfile/ >> /path/toyourlogfile/backups.log

and close your crontab terminal with :x
>> /path/toyourlogfile/mybackups. log is not mandatory it only needed if you want to be able too see the log of your backup in case of any error.
If you want to set different time in your cron I recommend you to use this tool is super easy and it will do the job.


If you need any help with custom web development don't hesitate to contact our web developing agency. We have over a decade experience in web development and we are the best web agency in Montreal. 

Read our articles for tips about Joomla Error, data leak or SSL/TLS.

Sidick Allaladé

Sidick Allalade, is Chief Technology Officer at Oshara INC and co-founder of the Osortoo web application. He loves solving complex IT problems, coding and everything IT. He has a good knowledge of online marketing and IT Governance, Audit and Security.
His experience spans hundreds of projects with companies of all sizes which makes him a valuable asset on any team.

Was this article useful?

People Who Read This Article Also Read...

How to install a Laravel web application that you cloned from Git

Laravel is a powerful php framework that allows you to create custom web applications

How to install a Laravel web a...

Everything You Need To Know About Communication Agencies

By definition, a communication agency (marketing) is a company that plans and harmonizes internal and / or external communication on be...

Everything You Need To Know Ab...

12 questions to ask when collecting customer data

Collecting data from customers is an important marketing strategy since it gives you information on what customers exactly want instead...

12 questions to ask when colle...

How to fix Joomla Error 0 'Cannot open file for writing log while updating'?

Did you already try udpating your joomla website and you got this error : "An error has occurred. 0 Cannot open file for writing log" ...

How to fix Joomla Error 0 'Can...

How Netlinking Is Useful for Your SEO

With the aim of helping companies improve their notoriety through their blogs. Oshara Inc, shares his knowledge about Netlinking in thi...

How Netlinking Is Useful for Y...

How to obtain instagram certification?

Like Twitter and Facebook, Instagram offers the possibility for administrators of an Instagram page to certify certain pages. Oshara In...

How to obtain instagram certif...