📜 ⬆️ ⬇️

Cheap cloud backup with encryption for home

I greet you, Habrayuzer! I'm going to tell you about the C14 cloud storage and a small utility that facilitates the routine work when working with the features of this storage.
image

Looking ahead to say that the cost of storing 1 TB is 2 euros per month. This storage has already been mentioned earlier on Habré: The nuclear bunker in Paris will be converted into a data center company online.net

C14 Storage


If you are familiar with C14, you can skip this part and go to the next one.

Online.net has a wide variety of services and several repositories. We are only interested in C14. Take money for storage, removal, opening of the archive. You can estimate your expenses approximately on their website. By operations we mean archiving, deleting and opening an archive with files.
')
The following scheme of work with storage is proposed:

We can create quite a few repositories in C14 (here, and hereinafter referred to as safe in their terminology). Each repository may have several archives. Archive (archive) - this is the OS with limited access. You can connect via sshfs, rsync, scp, ftp, webdav . The archive is available for connection within 2, 5 or 7 days, after that it will be automatically archived and placed very deep in the bunker. If you need to recover data, a new OS will be created and all your previously saved files will appear in the /buffer folder. If you try to change the restored archive, the contents will be copied and the archive will be updated.

C14 Backup Tool


A couple of words about BackInTime
Since BackInTime does not work in such conditions (due to the fact that copying hard links to files goes through a remote server by running rsync via ssh ), I want to automate and preserve data in the event of a fire, I wrote a program.

At first, I wanted to put all the code in one file, but the reality turned out to be much harsher, so I decided to share with all my decision.

What utility can:


What she does not know how:


Installation


To use you will need

rsync
encfs
sshfs
ssh


For xmpp logs you need composer (optional)

Downloading the script for those who do not have composer and do not need xmpp logs:

git clone https://github.com/TheSaturn/C14BackupTool.git
cd C14BackupTool
cp config.example.php config.php


Otherwise:

composer create-project thesaturn/c14-backup-tool
cp config.example.php config.php


Setup:


Register online at online.net . Add billing details . Generate ssh keys (if you don’t have them yet) via ssh-keygen . Edit config.php : you will need to enter the API key, select folders, etc. Run the script ( php /path/to/main.php profileName ) and wait for the message about the successful completion of the backup. Add script to cron at will

Cones:


API requests are not always applied instantly. Therefore, the code has a forced sleep() . Mounting over sshfs and connecting rsync does not always happen the first time either. The support throws up his hands and claims that everything is fine. Therefore, there are several attempts to connect to the repository.

A short version of the algorithm for those who want to understand better.
  1. Sending process start message
  2. Finding safe with the given name
  3. Searching the archive in safe where to put backups, if the latter was opened 6 days ago, a new one is created for 7 days
  4. Creating the necessary folders
  5. Mounting encfs (encrypted fs representation)
  6. File names included and excluded from backup are encrypted (otherwise rsync will not understand)
  7. Mount Storage
  8. Copying the encfs config
  9. Clearing the temporary backup folder (in case of unsuccessful backup there may be files there)
  10. Create hard links from past backup
  11. Sending a message about the beginning of this backup
  12. Rsync
  13. Rename temporary folder
  14. Record information about the date of successful backup creation in the description of the archive C14
  15. Sending a message that everything went well
  16. Unmounting sshfs and encfs


I will be glad to answer your questions. Link to the repository .

Source: https://habr.com/ru/post/325256/


All Articles