Synchronizing any folder on your system with OneDrive
In my last post: Backup regimes and synchronizing folders across your network, I discussed my method of backing up data from four folders off the root of the drive across my network and how I use the free SyncToy 2.1 tool from Microsoft.
So in this post I wanted to take it to the next level.
Introducing the Cloud
Here is the next bit of the puzzle.... Cloud storage. Everything so far has been based on local hard drives, but I have OneDrive storage and wanted to use that at least for My Documents and the Music and Pictures from my Media. This would make those three areas of my data available from anywhere I had an internet connection including my Windows Phone.
I am using Office 365 to provide Microsoft Office to the family (it allows 5 machines). It also provides 1TB of OneDrive storage per user.
When OneDrive is installed (or comes with Windows 8.1) it sets up a single folder in the user folders and will Synchronize anything in that folder with OneDrive storage in the cloud.
So how can I get OneDrive to synchronize with my folders C:\My Documents, C:\Media\Music and C:\Media\Pictures as well as the existing data (such as OneNote files and the phones camera roll).
One article I read on the topic, said to Pause Syncing by right clicking on the OneDrive icon in the system tray and then move the desired folders into the OneDrive folder and then resume Syncing. However, that MOVED the folders into a user folder: Exactly the thing I was trying to avoid by using folders off the drive's root folder. It would also break all the SyncToy configuration that I already have in place. So that is no good.
I wanted a method of mapping a folder from the data I want synchronized to the OneDrive folder.
Using a shortcut to the folder did not work as OneDrive just backed up the .lnk file. Most of the mapping techniques I found either mapped a network drive to a drive letter, or mounted a drive into an empty folder (the method I used with the micro SD card).
By then I found this article (and later this article) with the method I was looking for. It contained the command a "directory junction" on the Window NTFS File system. While the folder can point to a different location, OneDrive sees it as just another folder and will sync it as normal.
mklink /J "C:\Users\<USERNAME>\OneDrive\<Folder>" "C:\<Folder>"
Note: You will need to change the <USERNAME> and <Folder> placeholders. For older machines, you might find that the OneDrive folder is actually still called SkyDrive.
I used the %USERPROFILE% environment variable and a little bit of batch file logic to create a batch file which will create the links for me on demand.
I have attached the two batch files (one for the My Documents folder and one for the Media\Music and Media\Pictures folders) to the bottom of this article.
Here are some guidelines that I think will make the OneDrive approach to synchronization work better.
- Don't try to use both OneDrive synchronization and SyncToy synchronization at the same time for the same folders.
- I suggest moving your data out of the folder you are creating the link to, so the folder is initially empty. Then on each machine linked to the same OneDrive account, run the mklink command and wait for OneDrive status to say "Files are up to date".
- Then you can copy the files into the folder on one machine and let OneDrive upload them to the cloud storage. Then OneDrive on the other machines should bring the files down again. This should avoid the issue where OneDrive creates duplicates of the files when it finds files already existing.
- If you have a lot of data, you will be using a significant amount of your internet allowance (unless you are unlimited) to send and receive all the files to multiple machines.
- If your internet speed (especially upload speed) is slow, this process can take a long time for the initial upload and downloads.
Hope you found this information useful.
PS: After finding the process too slow and getting too many duplicated files, I decided to stick with my SyncToy method for the My Documents folder as it was faster and more reliable.
PPS: I am still uploading my Music and Pictures to a secondary OneDrive account that I don't use as a primary account on any machines. This is creates a "cloud" backup, but will not be synchronized to any other machines.