One of the most problematic tasks for a regular user is backup under Windows, which would ensure the closure of the following questions:
- fast (perfect in the background);
- would save both the current version of the files and the previous ones;
- file storage would not be available to viruses or natural disasters such as killing a carrier or stealing it;
- the contents of the backup would be available only to the user, i.e. has been polished.
There are many proposals for this, but none of them performs the tasks completely. Easy simple copying does not provide speed, fast saving does not provide reliability, copying to an external hard disk does not guarantee its theft.
However, there have long been tools for solving the problem. The main thing is to apply the Unix way and batch files. And the easiest option is to archive files into one archive and send it to the online storage using the command line. To speed up the work, the task is divided into 2 stages - first a full archive is created and sent to the online storage, then incremental archives are created as necessary, which gives speed. Encryption archives ensures data security.
What is required to solve the problem:
- Yandex account to access the Yandexdisk via webdav. The use of any other storage is not forbidden;
- 7z - console archiver, distributed free of charge;
- curl - a console tool for working with the Internet, is distributed free of charge.
For
portability , I put
7z.exe ,
7z.dll and
Curl.exe in one directory. Depending on how
Curl.exe was compiled, it may be necessary to put alongside or add libraries
libeay32.dll ,
libssh2.dll ,
msvcr100.dll ,
MSVCR110.dll to the system .
Further in this directory, it is desirable to create a directory in which you want to place the files and directories for the future archive. I have it called
“backup” and in it I put hard links to files or a directory link (the corresponding functionality is in FAR by the key combination Alt + F6). Thus, I can, without changing the structure of existing data, create a convenient structure for me to back up.
The next directory is
“temp” . Designed to store data archive before sending it to the server. At the same time, it will be an encrypted copy of the actual data, which provides them with an additional backup in case of a virus attack.
After that, in the source directory you need to create a fairly simple bat (cmd) file
“full.bat” with the following content:
@echo off set filebkp=work set pathbkp=backup set srvbkp=https://user:password@webdav.yandex.ru/backup/%filebkp% set pathtemp=temp set full=%filebkp%-full del /F /Q "%pathtemp%"\ 7z.exe a "%pathtemp%\%full%".7z -x!*.log; -r -mx1 "%pathbkp%\*" -ppass_for_archive curl.exe -k -X DELETE "%srvbkp%" --verbose -o .\stdout curl.exe -k -X MKCOL "%srvbkp%" --verbose -o .\stdout curl.exe -k -T "%pathtemp%\%full%".7z "%srvbkp%"/ --progress-bar --verbose -o .\stdout
- set filebkp = work - set the general name of the computer and the path on the server where the backup will be stored. Since There may be several computers, then this may be a backup copy of the work computer (work), home (home), laptop (book), specifying an individual name will not allow copies to be mixed with each other.
- set pathbkp = backup - specifies the path to the directory where the data is stored for backup, in this case, the directory with hard links and directory links, which you should have created earlier.
- set srvbkp = https: // user: password@webdav.yandex.ru/backup/%filebkp% - setting the directory on the server where the backup will be uploaded. user and password - passwords from your account on Yandex;
- set full =% filebkp% -full - set the name of the archive in advance.
- del / F / Q "% pathtemp%" \ - delete (clear) the temporary directory
- 7z.exe a "% pathtemp% \% full%". 7z -x! *. Log; -r -mx1 "% pathbkp% \ *" -p pass_for_archive - the launch string for the archiver. pass_for_archive - your password to the archive.
- curl.exe -k -X DELETE "% srvbkp%" --verbose -o. \ stdout — delete the destination directory on the server.
- curl.exe -k -X MKCOL "% srvbkp%" --verbose -o. \ stdout - re-create the destination directory on the server.
- curl.exe -k -T "% pathtemp% \% full%". 7z "% srvbkp%" / --progress-bar --verbose -o. \ stdout - fill the curl archive to the server.
Thus, by running the
“full.bat” script, you will receive the full version of your files in the archive in the
“temp” directory and its
“backup / work” directory on the server, encrypted with your password. This may take some time and has its limitations on the size of the archive, but the most important and at the same time daily changing data should be archived in this way.
Why important and daily changing? Because the following script,
“inc.bat” , allows you to find and send to the server in an incremental archive, modified data that differs from the full version:
@echo off set filebkp=work set pathbkp=..\backup set srvbkp=https://user:password@webdav.yandex.ru/backup/%filebkp% set pathtemp=..\temp set full=%filebkp%-full set inc=%filebkp%-inc set h=%TIME:~0,2% set m=%TIME:~3,2% set s=%TIME:~6,2% set ms=%TIME:~9,2% set curtime=%h%-%m%-%s% set dd=%DATE:~0,2% set mm=%DATE:~3,2% set yyyy=%DATE:~6,4% set curdate=%yyyy%-%mm%-%dd% set curdatetime=%curdate% %curtime% 7z.exe u "%pathtemp%\%full%".7z -x!*.log; -u- -up3q3r2x2y2z0w2!"%pathtemp%\%inc%".7z "%pathbkp%\*" -ppass_for_archive ren "%pathtemp%\%inc%".7z "%inc% %curdatetime%".7z curl.exe -k -T "%pathtemp%\%inc% %curdatetime%".7z "%srvbkp%"/ --progress-bar --verbose -o .\stdout
I think you can decrypt this file yourself - the script with the help of 7z analyzes the complete archive and source directory already present in
the temp directory, finds the changed files, packs them into an incremental archive named by the current date and time, and sends them to the server. Thus, if a full backup takes, say, 1 gigabyte and 3 minutes of time, then the modified files usually take 10-50 megabytes and fly to the server in a few seconds. By placing
“inc.bat” in the Windows Task Scheduler, you will allow this process to occur on a schedule at a convenient time for you, which will allow you to forget about it.
When it seems to you that the creation time of incremental backups has become too long, you can run
“full.bat” again - this will clear all directories from full and incremental archives and create a fresh version of the full version.