Many users think about creating regular backups of their data, and this is great! But how do you automate backups?

In this article we will work with the service * External FTP-repository»

FTP storage activation

This service is available in the relevant section of Billing. Choose «Dynamic tariff».

We specify the necessary amount of storage memory (up to 3.5Tb), for example, 50Gb, after which we add the tariff to the basket and pay.

A few seconds after payment service will be activated and visible in a special section.

We can get the data for working with it by selecting the service and clicking on the «Instructions» button.

In a separate window you will see a tab with all the necessary data to work.

Test shipment lftp

Now we go to our main server from which files will be downloaded to FTP storage. We will need the article «Working with FTP-repository».

We will need lftp. Installing the utility on Debian/Ubuntu is done using the

sudo apt-get -y install lftp

Great! Let’s try to upload the test file, but create it prematurely using the touch command.

Yes. Enter the command to upload the file:

lftp ftp://login:pass@backup.s1.fsn.spacecore.pro:21 -e "set ftp:ssl-allow no; put -O / file; quit"

login — storage user name.

pass — storage password.

backup.s1.fsn.spacecore.pro — shipment server (do not need to change).

/ — the directory where the file will be uploaded to the repository.

file — the file name to be shipped.

For our service this command will be relevant, enter.

lftp ftp://spacecore35176:KDAcfR4p1tyz@backup.s1.fsn.spacecore.pro:21 -e "set ftp:ssl-allow no; put -O / spacecore; quit"

After the input connection to the remote server and the file shipment (the time of shipment varies depending on the size of the transmitted file and the speed of the network). At the end of the process, we can see our file by connecting to the repository via FTP.

But the question remains: «How can this process be automated?».

First, create a script that will perform all the necessary actions for us. Create a file and open the editor using the command

nano backup.sh

Where backup.sh is the file name

#!/bin/bash
lftp ftp://spacecore35176:KDAcfR4p1tyz@backup.s1.fsn.spacecore.pro:21 -e "set ftp:ssl-allow no; put -O /backups backup.tar.gz; quit"

Where #!/bin/bash — the necessary string indicating that it is the shell script in front of us.

/backups — a new directory for storing the uploaded file in the repository (which must be created on the FTP server itself).

backup.tar.gz — the new file name for the shipment is premature.

Optionally, before uploading a file, you can add commands to archive those important data that you need to save on a remote server.

We save our script file using a combination Ctrl + X -> y.

Now we are trying to ship the file using a Shell script (in our case, an archive is specified for shipment backup.tar.gz , so let's create it first). Then we use our script.

sh backup.sh

Shipment’s started. Waiting for completion of the process.

The script works! Our data archive has been successfully uploaded to a remote FTP server.

Automation via CRONTAB

More information about working with CRON can be found in the form of public articles on various websites.

Use the command to open the CRON configuration.

crontab -e

Done. Currently it is empty. In the form of comments, information from the developers on setting up automation.

Minute Hour Day Month Money Weeks /Way/To/File

Add this line to set the regular start of our download script every day at 00:00 server time.

0 0 * * * /root/backup.sh

Where /root/backup.sh is the path to the executable.

Great job! We created our own script for uploading the backup file, and also learned to automate this task via CRON.

Last updated