K
K
karkir722019-08-03 11:13:00
Backup
karkir72, 2019-08-03 11:13:00

How to make a backup of files copied with replacement in Windows?

From one folder to another, you need to copy the files with the replacement. How can I automatically make copies of only those files that will be replaced? It is desirable that the folder structure be preserved so that, if necessary, copy them back with a replacement.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey c0re, 2019-08-03
@karkir72

1) you can use a normal version control system , for example, a system - git , there is a ready-made GitHub
service, look at the info on the network, videos on YouTube, everything will become clear how and what works.
2) you can write scripts yourself, for example, in PowerShell , something like this:

$BackupPath = "D:\SomeBackupPath"
$SourcePath="C:\Some\Source\Path"
$DestinationPath="C:\Some\Destionation\Path"
$7zip="C:\Program Files\7-Zip\7z.exe"

$SourceFiles = ( Get-ChildItem $SourcePath -Recurse -Force | where {$_.Mode -notlike 'd*'} | foreach {$_.FullName.Replace("$SourcePath\","") } )

$DestinationFiles = ( Get-ChildItem $DestinationPath -Recurse -Force | where {$_.Mode -notlike 'd*'} | foreach {$_.FullName.Replace("$DestinationPath\","") } )

$ToPackFiles = @()

$SourceFiles | foreach { if ($DestinationFiles -match "^"+ $_.Replace("\","\\") +"$") { $ToPackFiles += "'$_'" } }

cd $DestinationPath

if ($ToPackFiles) { $ToPackFiles | & $7zip a -mx9 ("$BackupPath\"+(Get-Date -Format "yyyy-MM-dd_HHmmss")+".7z") }

Copy-Item "$SourcePath\*" -Recurse $DestinationPath -Force -PassThru | foreach { Write-Host $_.FullName }

posted on GitHub - BackupAndCopy.ps1
script takes files from SourcePath compares with DestinationPath, if there are matching ones, then packs matching files from DestinationPath in 7z archive to BackupPath folder (file name date + time)
and then copies files from SourcePath to DestinationPath
PS: in 7zip must be installed on the system, specify the path to it in the $7zip variable
Also see ZPAQ , it supports file versioning, i.e. inside one archive, for example, 10 copies of the same file with different modification dates can be saved.
the script, fixed some bugs (comparing hidden files, packing extra files)

D
Diman89, 2019-08-03
@Diman89

Total Commander will help - if the names match, it will ask what to do, and you can answer it "automatically rename existing files"

K
Konstantin Tsvetkov, 2019-08-03
@tsklab

FAR5d454c8a4ab0e467693353.png
Explorer:5d454d5c9e1ab028416680.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question