How to sync two disks on a computer. Convenient file synchronization

The directory is read using the get-childitem command. The -recurse option is added to include subfolders to be counted, and the PSIsContainer () function is used to distinguish files from folders. If it returns True, then the item is a folder, otherwise it is a regular file:

$ source \u003d ¨c: files¨

$ srcfolder \u003d get-childitem $ source -recurse | where-object ($ _. psiscontainer)

$ srcfiles \u003d get-childitem $ source -recurse | where-object (! $ _. pciscontainer)

To solve our simple task, four lists are required: the first two contain the source files and folders, and the remaining two contain the resulting files and folders. The synchronization process boils down to iterating over these lists and copying files from one folder to another.

The first loop checks if the source directories exist in the backup folder, and if they do not already exist, they are created using the new-item command.

foreach ($ folder in $ srcfolders)

$ srcpath \u003d $ source -replace ¨ \\ ¨, ¨ \\ ¨ -replace ¨: ¨, ¨: ¨

$ dstpath \u003d $ folder.fullname -replace $ srcpath, $ destination

if ($ dstpath -ne ¨¨) (

if (! (test-path $ dstpath))

¨Creating the ‘$ dstpath’ folder.

new-item $ dstpath -type directory | out-null

A very similar loop is performed when comparing the resulting and original folder list, thereby creating an exact structure of subfolders. The other two loops process files: the first one copies the updated objects from the source to the target folder, the second - those that are not in the source directory - from the final one. You can find out if a file has been updated by its hash code. Note that because files are opened read-only, they are not blocked from being used by other programs. However, according to the rules of good taste, the file must be closed with the Close () function at the end of the hash code calculation:

$ md5 \u003d new-object system.security.cryptography.md5cryptoserviceprovider

$ fs \u003d new-object system.io.filestream ($ file, $ mode, $ access)

$ hash \u003d $ md5.computehash ($ fs) # file hash code

$ fs.close ()

It is pointless to overwrite a newer file with its old copy, and therefore we will add commands to compare modification dates. When moving back files that are not in the source folder, no checks are required, just execute the copy-item instruction. The entire script is shown in the listing - the paths to the source and destination folders are passed to it (do not forget to add closing slashes, for example, c: filessource), and then it does all the work on its own and only displays information on what is happening on the screen. Note, even if you have not previously created the resulting folder, the script will create it on its own:

if (! (test-path $ destination))

new-item $ destination -type directory -force | out-null

So, this script will help you copy photos, tables, text documents, etc. that are not on a flash drive, without wasting time on manual file-by-file comparison. To use it, you can create a simple BAT file on the Desktop by specifying a command of the form powershell.backup.ps1 c: filessrc d: backup (the path to the script usually needs to be given in full). It is easy to sync folders later by clicking on this batch file. Recall that the command Set-ExecutionPolicy RemoteSigned, executed on behalf of the "Administrator", allows execution of unsigned scripts.

Keeping copies of important files in a completely unprotected form is perhaps not entirely correct from a security point of view. Windows 7, despite Microsoft's best efforts, remains vulnerable to viruses, worms, and other malware. They get to documents that are constantly, in fact, in the public domain without any problems. Fortunately, a very useful feature has appeared in the operating system - virtual disks that are mounted and disconnected on the fly. They are also suitable for backing up any important files that can be accessed by a limited number of users.

A virtual disk is presented in the system as a VHD (Virtual HardDisk) file, which has a complete structure and content similar to those of a hard disk. It is created using the Windows 7 built-in computer management utility that runs through the compmgmt.msc module. In the window of this program, click on the "Disk Management" line and select the "Action Create virtual disk" command from the menu. The new virtual disk is sized and then the volume is formatted. In the last step, you can assign a drive letter or bind the VHD file to an NTFS folder.

The last method is interesting because copying is allowed to a specific folder, regardless of where the virtual volume is located. By unmounting a virtual volume in a computer management utility, you can be sure that neither viruses nor curious users will get to the most recent copy of important documents. The virtual volume itself, that is, the file with the VHD extension, can be copied to the backup media. An additional security measure is virtual volume encryption, which is available using BitLocker to users of the maximum and business versions of Windows 7. When connecting such a protected volume (and it can be used on other PCs, even where BitLocker is not installed), Windows will ask for a login and password.

About two years ago I gave birth to a project - a small client program that can be installed on any device and simply synchronizes files.
For example, you could specify that documents will be synchronized between your home and work computers. Music and books between your home computer and your phone. Backups between home computer, work computer and server. Also, this program could control the subsequent distribution of any file in the system. That is, as the owner, you could always find out the history of the file: copying to a USB flash drive, to another computer, by "email", etc.

Then I almost got funding, but the investment fund with which I worked at the last moment demanded a serious stake in the business. And I decided that the game was not worth the candle. And then somehow it was not up to that.

Yes, you say, there are cloud storage and why is it needed when there is Yandex.Disk, Dropbox and a bunch of cloud file storage services. Well, it's just not always acceptable and convenient. Minuses:
1. You trust your files to a third party without any guarantees. (I'm not paranoid, but you won't leave your private data in such storage)
2. You need the Internet to access them. And this in Russia is still not always possible with the required speed.

A holy place is never empty and BitTorrent has released something similar, but in a stripped down form. Their program simply syncs files between different platforms and systems as soon as they go online or are inside the same subnet. Unfortunately, you cannot flexibly configure synchronization rules, but there is an excellent client that is administered through either the native interface (WIndows, MAC OS X, Android, iOS), or through the web interface (* NIX).

I no longer climb for photos, documents and music on my mobile and do not climb onto the server to pick up a rarely updated backup.
There are several folders on your home computer:
Telephone
Server
General
Auto

To put something on my phone, I just copy the file I want to the Phone folder. It will appear on my phone in a few seconds
To exchange documents with the guys at work, I throw it into a shared folder. And after a few seconds, this file appears for all the people I need - locally and not in the cloud.

In the car, there is a Google Nexus as a media center, it looks at the Internet via 3G. On my home computer, I throw navigation maps and music into the Auto folder. Everything is automatically folded into the car. From the Auto / Registrar folder, I take interesting moments captured by the video recorder (the device in the car is always online).
Saves tons of time.

We wish BotTorrent every success in developing their wonderful project.
Downloading.
Available on Google Play Market and Apple AppStor. I think it will soon appear for a mobile version of Windows.

PS
Thanks to Murin Sasha for the tip)

After the article about exclusively manual method of folder synchronization there were requests to find and describe a "lazy" solution to this issue. Keep - a free program for automatic folder synchronization called Allway sync.

Why sync folders

This question surprised me by some users in the comments and mail - I answer them. You may need it ...

  • if you want to be on the safe side after the transfer any system folder or temporary data to another disk
  • if there was not enough time to finish a project at work / at home (came home / to work, plugged in a USB flash drive and are already working with automatically updated data)
  • if you need to store a backup of important data on an external storage medium (hard disk, ssd-drive, flash drive ...)
  • if you need to quickly and losslessly provide data exchange between several computers
  • to facilitate and speed up manual copying of data between folders and disks

Automatic folder sync

The Allway Sync program, as the manufacturers themselves assure us, “uses innovative algorithms for synchronizing your data between desktops, laptops, USB drives, remote FTP / SFTP and WebDAV servers, various online data warehouses and so on. Data compression and encryption are supported. It combines bulletproof reliability with an extremely simple interface. "

Well, they managed to intrigue us, right? Let's put their application to the test.

Installing Allway Sync

There is nothing terrible or confusing about it. Only two nuances - NOT uncheck the installation special service (needed to automatically track changes in folders) ...

... and also decide if you need desktop shortcut and do you install the program for all users of your computer ...



Setting up and working with Allway Sync

Immediately after installing the program, you need to teach it your language ...

I will show the rest of the program settings as it is tested. So, by default we already have some kind of task called "New Job 1" - right-click on the tab and create our own personal new task ...

After that, you can rename or delete any task in the same way. With this figured out - go ahead and specify the folders for synchronization ...

... we decide on the direction of synchronization (the "Change" link between the arrows in the middle) ...

Caution! Useful additional information on the website:

(default is general sync)

If you, like me in this case, have the second folder on a USB flash drive, I recommend pressing the "Configure ..." button and check the box to link the program to the characteristics of the drive ...

As you can see, they explain everything competently and clearly to us literally at every step in this wonderful program.

Primary manual sync

I press the Analyze button, read the warning and ignore it ...

... then, finally, I sync the folders ...

Opening in explorer tabs both experimental folders at once, checked the result of the Allway Sync program - everything is clear and without errors (how many files in one folder, so many in the second).

That's all well and good, but it was just manual sync - where is the automatic sync? I'm telling you.

Automatic data synchronization

We go into the settings of our task, which can be accessed in several ways ...

  • item "View" in the program menu and "Settings ..."
  • right-click on the task tab and in the context menu the "Properties" item
  • in english keyboard layout click "Hotkeys Ctrl + O (sequentially, no plus)

(by the way, here and program autostart can be turned on)

... at the very bottom of the list of settings, on the left in the window, we look for our task and go to "Automatic synchronization" ...

... and here you can customize it for yourself, whatever you like - when you connect the drive to your computer, after a certain period of time, when you start the application, before exiting ...

The variety of conditions for automatic folder synchronization in this program is simply amazing - the authors have foreseen most of the wishes of users.

I set the first condition ("When a removable device is connected") and removing the flash drive from the laptop deleted three photos in the test folder. After connecting the drive to the computer, the data was automatically instantly synchronized ...

Today my story will be dedicated to data synchronization programs between PCs and we will not talk about cloud services, although some of the utilities provide such an opportunity. Those users who are interested in "clouds" like Dropbox, let them go to the article, and we will look at programs for creating local copies of files and folders between user computers (on USB HDD, flash drives, in a local network, etc.), without resorting to help of a remote server. This solution is suitable for people who doubt the safety of their data on the cloud service and its servers, it is not known where they are located. Consider at least one of the founders of Apple - Steve Wozniak, who prefers to store data locally on the device, ignoring iCloud. It is to these users that this article on data synchronization will be devoted.

GoodSync

For example, the GoodSync utility is so versatile that it can work both as a regular backup program, and as an intermediary between a local PC and cloud services for synchronizing data, as well as a tool for working with files on two computers, making changes to data if they were performed on any of 2 PCs. Accordingly, you will always work with the current file. The connection between the user's computers is carried out directly, using the GoodSync Connect function, that is, without using cloud services.

For the program to function properly, install it on the machines where you need data synchronization... In order not to get confused, each task has its own type - backup or synchronization. In the second case, changes in files from both computers or used media will be tracked. Other PCs with GoodSync installed, your FTP server, a computer from your home network, or services that support the WebDAV protocol can be used as such media, as well as the following cloud services: Google Drive, Microsoft SkyDrive, Windows Azure, Amazon S3 and Amazon Cloud Drive.

Having decided on the data source and storage location, you can analyze the files in the folders that you have selected right in the GoodSync program window so that you don't miss anything before synchronization. If you find identical files or similar ones, by comparing them, you can choose the direction (from where / where) to copy them.

Lovers of task automation, you can set up a schedule for data synchronization with a PC... For example, before shutting down from a PC or at a certain time. GoodSync is able to independently overwrite the old file with its new revision if necessary. If you have doubts about the correctness of file transfer over the network, the program allows you to compare the checksums of files.

File synchronization is the process by which two or more folders contain. When you add, delete or change any file in one folder, during synchronization it will be added, deleted or changed in all other folders.

In other words, the file synchronization mechanism is designed to work with data from different workstations synchronously, without the use of removable media - flash cards or disks.

The actual result of file synchronization is the synchronization of the same version of the file with the most recent date of its creation or modification in all synchronized folders.

How do I sync files and folders?

The essence of file synchronization comes down to registering on one of the so-called cloud services that allow you to synchronize files, and then moving user data to the server of such a service.

Currently, there is a rapid development of cloud services, which, in the struggle for users, provide a variety of additional services. On average, the services offer up to 10 GB of free cloud storage for file syncing. This volume is quite enough to store the most important information.

The most popular storage services are Dropbox, SkyDrive, Yandex Drive, SugarSync, Mail.ru Cloud and Google Drive.
In order to synchronize all devices, you must install a special program on each of them, which can be downloaded from one of the services. This program will create a user folder in which all documents will be stored. They will be uploaded to a special storage on the Internet, from which they will be available to the user anywhere in the world.

Synchronization can help ensure that files are identical across devices that are connected to the same cloud service. For example, if information changes in one of the files on the server, this file will be automatically updated on all computers connected to the synchronization service.

Data Synchronization Benefits

The main benefit of synchronization is data protection. Even if the computer breaks down or the flash card is lost, the documents will be safe on the server.

Synchronization also opens up new possibilities for easy file exchange between users. To do this, you need to send a link to the required document, after which it will be available to another user through it.

Another key benefit of syncing data is the ability to work with the same information across devices without having to worry about constantly transferring it.