Script to automate backups

We share with you a script prepared by one of our readers to carry out backup copies automatically. One more chance to learn to use the terminal and develop scripts customized. 🙂

This is a contribution from Daniel Durante, thus becoming one of the winners of our weekly competition: «Share what you know about Linux«. Congratulations Daniel!

Functionality

  • Make backups using the rsync command.
  • Use a bash script.
  • The current version only allows use locally.

Requirements and Installation

For the script to work, the system must have the gdialog application.

It does not require installation, simply place the script in the $ HOME / .copies / directory. This parameter is located in the variable script_directory and can be changed.

Selecting the source and destination directories for the copy

In the current version they are specified by editing the copies.sh script. The format used makes use of the -acv and -delete options.

For example:

rsync -acv --delete $ user_directory'directory_to_backup '$ target_directory

where we will replace directory_to_back up with the name of the desired directory.

The variable $ user_directory is assigned a value in the script.

The variable $ destination_directory is assigned the value read in copies.cfg

Configuration file

The configuration file is called copies.cfg and is located in the directory $ HOME / .copies /

Configuration file structure

The second line specifies the destination of the backup:

#Destination / media / Iomega_HDD /

Files Accessories

The copy_ini.sh script file checks if backups have been made with a periodicity interval. Currently there is no parameter in the configuration file to specify this, which is set in the same script daily.

Automate the backup process

1.- Put in cron with the crontab -e command in a similar way to the following:

# mh dom mon dow command
0 20 * * * DISPLAY = »: 0 ″ ​​/home/user/.copies/copias.sh

In this example, the execution of the script would be launched at 20:00 hours each day

2.- Add to the programs to be executed at the beginning the script copies_ini.sh indicating the full path to it


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Daniel Coke said

    The good thing about Deja Dup is that it has encryption to save the files, it is very good, but to this script you can add that with gnupg + split and it is almost the same.

    Nice article guys.

  2.   Let's use Linux said

    Sure ... for those who want to use a graphical interface ...
    Others prefer to do it "the old fashioned way"
    Cheers! Paul.

    2012/11/30

  3.   Edwardx123 said

    It's easier Deja-Dup

  4.   MiguelH said

    Hello, and if I want to do the backup on a PC connected to the same network. How would you put the destination in the config file?