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.
Notes
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.
David
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.
Comments
Anonymous
September 11, 2014
IMHO, needing them to be in the root folder makes this more difficult than it needs to be. For all non-work PCs OneDrive is the default documents folder. Once you manually change the various built-in library folders (pictures, videos, etc...) to point to a OneDrive folder then new items will automatically be backed up to OneDrive. Let it spend the first half day syncing up whatever monster music collection you have (lots of files = lots of overhead). Once it's done you'll never lose them. File History can serve a similar backup function - I used to back up to an external usb drive attached to my wifi router but honestly see no need any more as long as I use the folders designated by the operating system for documents, videos, pics, etc... OneDrive is more than enough.Anonymous
September 11, 2014
Hi old coder The default folders put the documents, pictures, music etc. into a user folder which is not easily accessible when you log into the machine as a different user. A few of the machines in my network are accessed by multiple users and we want all the files accessible regardless of user used. As long as it works for you, that's great. DavidAnonymous
December 27, 2014
Thanks a bunch for the tip, David! I have over 150GB of images for my landscape photography work and your symlink solution worked to get OneDrive to back them up. I have my images on a separate SSD from my boot disk so I was forced to send them to OneDrive manually (what a pain!) but this way I was able to link my SyncToy nightly backup directory on my local RAID array to OneDrive and have everything automatically upload.Anonymous
January 10, 2015
HI, Isn't there a way to right click on a folder/file through ms explorer and select (i forgot the exact term) "sync with onedrive" or something? I KNOW i was able to do it a while back but since then I have replaced my primary OS Disk then recently had another storage disk fail on me, fortunately I had one of the folders on that failed disk linked to onedrive so it alone was saved, Unfortunately that was the only folder saved, anyway How do i get that right-click option back? The folder wasn't moved to the onedrive folder and I don't remember doing anything with cmd or outside apps just right-click folder and sync.... I can't seem to find what it on a google search.Anonymous
January 19, 2015
Seems symlinks are no longer supported by OneDrive in Windows 8.1Anonymous
January 29, 2015
Thanks for the warning NK, was just about to try this on 8.1.Anonymous
January 30, 2015
I had it working fine with Windows 8.1 when the article was written. The article even references Windows 8.1. NK and BB, I suggest you try it again. DavidAnonymous
January 31, 2015
I will try again, but my first attempt failed, and then I saw this as confirmation: www.howtogeek.com/.../how-to-sync-any-folder-with-skydrive-on-windows-8.1Anonymous
June 21, 2015
As it turns out - Directory Junctions can only be used on local volumes. Network drives cannot be mapped using mklink - which is sad. So I guess, the headline should be changed to read; synchronizing-almost-any-folder-on-your-system-with-onedriveAnonymous
January 02, 2016
wow your making this way more complex than it actually is man...Anonymous
January 29, 2016
I have a NAS storage server, is there a way to map the drives to a folder and have it sync to Onedrive.Anonymous
May 17, 2016
I think it's confirmed below but I've tried this on Windows10 to an external HDD. It appears to only work one way. I can add files to OneDrive and they appear everywhere, but if I add them to the external HDD they are not replicated to OneDrive. Is this expected or have I missed something? I've tried the same with the folder elsewhere on an internal HDD and it all works OK as expected.Anonymous
May 25, 2016
Thank you very much, this is exactly what I was looking for, and it works perfectly!Anonymous
June 01, 2016
Awesome, thanks for this!Anonymous
August 09, 2016
I am trying to get onedrive windows 10 to sync a folder which is located on a Synology NAS network drive. Can someone please confirm whether or not windows 10 allows mklink to create a folder link inside c:/onedrive to trick onedrive into syncing the folder on the network drive?Thanks- Anonymous
August 15, 2016
It can but the problem is that if you'd ever have to reset the OneDrive sync it will look at how much data is stored in the cloud and compare it to how much space is available on the drive holding the root OneDrive folder. The cloud storage can be larger than your root drive because you've faked it into backing up your NAS storage via the junction. So junctions are cool but OneDrive is too clever about protecting the user. I have Office 365 with 1TB, a 100GB SSD in my laptop (C:) and my pictures, music, videos on a HD in the drive bay (D:). After a reset on OneDrive I can no longer sync everything because it says there is not enough room on C: even though I've junctioned all the big stuff to D:. My solution seems to be to move my OneDrive root to D: and junction Documents to C:. This should work as I have enough free space on D:. But what a pain!
- Anonymous
Anonymous
December 14, 2016
This is a great help to adding other folders to be synced to OneDrive. Thanks! I have one question, though: It's my understanding that if a folder is deleted in OneDrive, then it will be deleted in the cloud and that deletion will be propagated to any other computers linked to the OneDrive account. For instance, if I sync my Desktop folder using "mklink /J "%USERPROFILE%\OneDrive\My Desktop" "%USERPROFILE%\Desktop", how can I remove the OneDrive synchronization without deleting the My Desktop folder and its contents?- Anonymous
February 16, 2017
By removing the Symlink you created in %USERPROFILE%\OneDrive with that command like any usual file the original "My Desktop" Folder will not be deleted!(Remove "%USERPROFILE%\OneDrive\My Desktop" it's a symbolic link not the original folder)- Anonymous
February 16, 2017
Thanks Greg.David
- Anonymous
- Anonymous
Anonymous
January 19, 2017
In Windows 10, mklink cannot link a network drive. Always got "local volumes are required to complete the operation", but external hard drive works.Not sure it's just me or some changes Micro$oft made.Hao- Anonymous
February 16, 2017
You can change this behavior by configuring the following Group Policy setting:Computer Configuration\Administrative Templates\System\NTFS File System\Selectively Allow The Evaluation Of A SymbolicLinkWhen you enable this policy setting, you can select from four settings:Local Link To Local Target Enabled by default, this allows local symbolic links to targets on the local file system.Local Link To Remote Target Enabled by default, this allows local symbolic links to targets on shared folders.Remote Link To Remote Target Disabled by default, this allows remote symbolic links to remote targets on shared folders.Remote Link To Local Target Disabled by default, this allows remote symbolic links to remote targets on shared folders.http://sourcedaddy.com/windows-7/how-to-create-symbolic-links-to-shared-folders.html
- Anonymous
Anonymous
February 16, 2017
You are brilliantAnonymous
February 16, 2017
You are brilliantAnonymous
May 31, 2017
guys,this is wrongmklink /J “C:\Users\OneDrive\” “C:\”it should bemklink /J "C:\Full\Path\Link to be created" "C:\Full\Path\To\OneDrive\Existing Target Name"otherwise junction link will not be synced...- Anonymous
May 31, 2017
Hi mackarof I have folders off my c:\ drive root which I don't want to move, but do want to have synchronized.So I have added the directory symbolic links to the OneDrive folder pointing to the existing folders.You are going the other way. Existing OneDrive folder made available off root folder.This might work better for automatically synchronise, but the synchronising does work the way I have it, but it does not always start immediately. If it does not, you can always pause and resume the Onedrive process to make it sync.Thanks for your comments.David
- Anonymous
Anonymous
December 10, 2017
This is a lot of work to use OneDrive!Anonymous
February 16, 2018
Thanks a lot. The article is really helpful.Anonymous
May 18, 2018
I am not very skilled at this level. Will this work if the folder I want to have synced (copied/saved in the cloud on OneDrive) is on my desktop or do I have to move it directly to my C: ??- Anonymous
May 18, 2018
I figured it out; I think. I did not have to do anything with mapping. I just hadn't synched in so long, that when I asked Cortana for help, she lead me the way. All I needed to do was drag & drop or copy and paste. I had already created the folder in OneDrive with the same name as the desktop folder. Now everything is up to date. Now I just need to figure out how to properly set up my Seagate.
- Anonymous
Anonymous
August 16, 2018
Thanks for this! This post is over 4 years old. It kind of blows my mind that OneDrive still requires the creation of a symbolic link to function the way I need it to.I have re-purposed your script for my own needs:1) User has c:\Projects that should be backed up.2) User's Desktop should be backed up.3) Company OneDrive folder is "OneDrive - SIE" (different path)=============================================@cls@echo This will create mappings to your OneDrive - SIE folder (Press Ctrl-C to abort)@pauseif not exist "%USERPROFILE%\OneDrive - SIE\Projects" md "%USERPROFILE%\OneDrive - SIE\Projects"mklink /J "%USERPROFILE%\OneDrive - SIE\Projects" "C:\Projects"if not exist "%USERPROFILE%\OneDrive - SIE\Desktop" md "%USERPROFILE%\OneDrive -SIE\Desktop"mklink /J "%USERPROFILE%\OneDrive - SIE\Desktop" "%USERPROFILE%\Desktop"@pause====================================================Anonymous
June 22, 2019
Thanks for the hint! All these years later and this approach is still the only way to get folders outside one drive folder to sync. Can't believe @Microsoft has still not enable this feature.