Sunday 3 March 2019

windows - Incremental backup with 7zip (follow up clarifications seeked)

For anyone Googling to get a working, complex, 7-zip differential backup going from the cmd.exe prompt... Here is my wallets backup script "C Backup Wallets (7zip) (Differential).bat". It will search my C:-disk for any cryptocurrency wallet files (*.dat, *.old, *.bak) and back them up to my E:-disk.


@echo off
cd "C:\Program Files\7-Zip\"

set base_archive=E:\= RAIN\= CRYPTO\== Wallet Backups\= 7zip Differential Backups\Wallets C-Disk.7z
set archive_folder=E:\= RAIN\= CRYPTO\== Wallet Backups\= 7zip Differential Backups
set file_list="C:\*wallet*.dat" "C:\*wallet*.bak" "C:\*wallet*.old" "C:\*.conf"

echo Output folder is %archive_folder%
echo Main archive name is %base_archive%
echo Looking on C: for %file_list%
echo.
echo.
REM pause

IF EXIST "%base_archive%" GOTO create_differentials ELSE GOTO create_main_archive

:create_main_archive
echo %base_archive% for C: not found! Creating it next... Hold on!
echo.
echo.
REM pause
7z u "%base_archive%" -xr!Microsoft\* -xr!windows\* -xr!?Recycle.Bin\* -r %file_list%
goto :eof

:create_differentials
echo %base_archive% for C: found, updating any changed or new files (even when in use)... Hold on!
echo.
echo.
REM pause
7za u -mx9 -slp -snh -snl -ssw "%base_archive%" -xr!windows\* -r %file_list% -u- -up0q3r2x2y2z0w2!"%archive_folder%\Wallets C-Disk %DATE:~-4%-%DATE:~7,2%-%DATE:~4,2%_%TIME:~0,2%h%TIME:~3,2%.7z"
goto :eof

REM https://sourceforge.net/p/sevenzip/discussion/45798/thread/1e2eefc3be/
REM 7za u -mx9 -slp -snh -snl -sns -ssw "E:\= RAIN\= CRYPTO\== Wallet Backups\= 7zip Differential Backups\Wallets C-Disk.7z" -xr!windows\* -r "C:\*wallet*.dat" "C:\*wallet*.bak" "C:\*wallet*.old" "C:\*.conf" -u- -up0q3r2x2y2z0w2!"E:\= RAIN\= CRYPTO\== Wallet Backups\= 7zip Differential Backups\Wallets C-Disk %DATE:~-4%-%DATE:~7,2%-%DATE:~4,2%_%TIME:~0,2%h%TIME:~3,2%.7z"

:eof

What this script does is: 1. look on C:-disk, including subfolders (-r) for everything matching walletdat, walletold and walletbak 2. look for base backup archive. If it does not exist, create it 3. when making a difference file for the backup, the resulting archive name will contain the date and time of the archive. THIS MIGHT FAIL in giving yyyyMMdd file names if your locale is set differently than US... I have not tested this.


PS: 7za is not installed by default; both x86 and x64 are available as extra download on the 7-zip website. The output files of the differential zip files look like this: Wallet C-Disk 2019-09-13_13h53.7z. I will check why that is and correct where needed.




Original question:


In follow up of: https://superuser.com/a/1382918/225479


Question if I may... I am on Windows 10, in the cmd prompt and I try to make differential backups of all my wallets.


Whatever I try, I never get the existing archive.7z-file, only the new differential.7z-file. And after a second run, I will get an error that the new differential.7z file already exists...


I tried:


C:\Program Files\7-Zip>7z u  "{existing archive.7z}" -u- -"up0q3r2x2y2z0w2!{new differential.7z}" -r "C:\*wallet*.dat"

and


7z u  "{c:\temp\existing archive.7z}" -u- -"up0q3r2x2y2z0w2!{c:\temp\new differential.7z}" -r "C:\*wallet*.dat"

and 7z u "c:\temp\existing archive.7z" -u- -"up0q3r2x2y2z0w2!c:\temp\new differential.7z" -r "C:\*wallet*.dat".


From another site I tried this:


7z u c:\temp\basefile.7z -r c:\*wallet*.dat -u- -up0q3r2x2y2z0w2!c:\temp\differential.7z

And many more variations. The basefile / existing archive.7z-file is never made... Why? What am I fracking up here, pretty please? :/ I assume this 1 command should do it all; create an archive when no archive exists and if it exists only update the differences... No? Are the wildcards the problem here?


Post-edit: some more testing... I now tested this one: 7z u c:\temp\basefile.7z -r c:\temp\ -u- -up0q3r2x2y2z0w2!c:\temp\differential.7z (find all folders on C: that contain temp in their name and compress them). It ONLY makes the differential.7z file, NEVER the basefile.7z. IF I provide the basefile.7z myself, the command creates the differential.7z file which will have the same size as my self-provided basefile.z7 (so it stores everything again, instead of only the differences). IF a differential.7z already exists, the command fails because the file differential.7z already exists...


Post-edit continued: just for giggles I ran 7z u "c:\temp\existing archive.7z" -r "C:\*wallet*.dat" -ms=off followed by 7z u "c:\temp\existing archive.7z" -u- -"up0q3r2x2y2z0w2!c:\temp\new differential.7z" -r "C:\*wallet*.dat" -ms=off. The first differential file now was correct. But I could not run it for a second time to create a 2nd differential file.


So... my main conlusions for now are: 1. you need to create the existing archive.7z first (in a separate batch file so to speak)? Once that base archive is made, you can run ONE incremental backup, so 2. you need to expand the command to add time and date stamps to the incremental files (either with 7zip or with some batch scripting). Am I correct? :)

No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...