Backup your system using a simple Shell Scripts

Backup your system using a simple Shell Scripts

by Sidick Allaladé on 13/02/2020 |

Updated at 27/10/2020


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:

#!/bin/

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'

NOW let's Executing the Script

Name your file 'backup.sh'
To execute it you need to opne terminal prompt and start with a dot '.' so if you name your file backup.sh you will do .backup.sh
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/backup.sh >> /path/toyourlogfile/backups.log

and close your crontab terminal with :x
NOTE:
>> /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. 

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...

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...


How to install Laravel project you cloned from Git

Laravel is a powerful php framework and as its slogan says it is “The PHP Framework for Web Artisans”.

How to install Laravel project...


Is ETL Still Relevant in 2019?

ETL is an abbreviation for extract, transform, and load. It is one of data integration tools used in the extraction of data from a sour...

Is ETL Still Relevant in 2019?


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 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...


This is How you can Simplify Complex Enterprise Workflows in Your Business

A workflow is a repeatable scheme or pattern of a sequence of steps or activities that are undertaken to realize the completion of a pa...

This is How you can Simplify C...


×