# Local sync with NextCloud

**URL:** <https://help.nextcloud.com/t/local-sync-with-nextcloud/8973>\
**Category:** 📱 Desktop & mobile clients\
**Created:** [February 15, 2017, 9:44pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973 "2017-02-15T21:44:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![harlandraka](https://help.nextcloud.com/letter_avatar/harlandraka/32/6_22734026db12803ebb3e059622ac3534.png) [@harlandraka](https://help.nextcloud.com/u/harlandraka)\
**Post date:** [February 15, 2017, 9:44pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/1 "2017-02-15T21:44:24Z")

</div>

I installed NextCloud 11 on my server. In that server, I have a 300GB folder which I would like to sync. Since it is already on the server, can we skip online sync and do an offline sync, improving speed?

I’m not talking about connecting to localhost and syncing data like that, because it still relies on a connection, I would like to manually tell nextcloud “take this folder and import it into user X directory”. Is it possible?

---

<div class="post-metadata">

**Author:** ![JasonBayton](https://help.nextcloud.com/user_avatar/help.nextcloud.com/jasonbayton/32/297_2.png) [@JasonBayton](https://help.nextcloud.com/u/JasonBayton)\
**Post date:** [February 15, 2017, 11:41pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/2 "2017-02-15T23:41:23Z")

</div>

Can you provide a little more context?

- What and where is user x directory?
- What protocol are you looking to use in place of http?

---

<div class="post-metadata">

**Author:** ![harlandraka](https://help.nextcloud.com/letter_avatar/harlandraka/32/6_22734026db12803ebb3e059622ac3534.png) [@harlandraka](https://help.nextcloud.com/u/harlandraka)\
**Post date:** [February 15, 2017, 11:49pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/3 "2017-02-15T23:49:57Z")

</div>

Right now I’m using the DAV way to connect with cURL under debian. I’m connecting to localhost, providing cURL the full path of the file I want to upload, along with the full path of where it should be located in the server.

```
curl --insecure -T /path/to/local/file.zip --user user1:password https://localhost/remote.php/dav/files/user1/path/to/remote/file.zip

```

I was looking for a way which didn’t involve cURL. I don’t know, maybe a binary or an executable inside the nextcloud directory which allows to batch import an entire folder of your choice into an existing user’s account

---

<div class="post-metadata">

**Author:** ![JasonBayton](https://help.nextcloud.com/user_avatar/help.nextcloud.com/jasonbayton/32/297_2.png) [@JasonBayton](https://help.nextcloud.com/u/JasonBayton)\
**Post date:** [February 16, 2017, 12:01am UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/4 "2017-02-16T00:01:01Z")

</div>

If I’m following correctly, the directory you wish to import is on the server, and you’d like to move/copy it directly into a user account?

If that’s the case as a one-off;

- rsync, cp or mv the data directory into `/path/to/nextcloud/data/username/files/` (symlinks aren’t supported)
- from the `/path/to/nextcloud` directory, run `sudo -u www-data php occ files:scan --user` (or `--all` if you do this multiple times to different users)

Where `user` in both instances is the user in question. This will import the folder to the root of the NC data dir for the user (the folder will sit alongside Documents, etc) and force Nextcloud to scan and import it into the database. _This should not be done frequently_. Return to webdav or the webUI going forward as changing the filesystem regularly unbeknownst to Nextcloud can lead to database mismatches.

Alternatively, you can add the directory on the server _in place_ as external storage within the NC UI. It doesn’t matter how often you change the underlying filesystem in that case as external storage is regularly scanned for changes.

---

<div class="post-metadata">

**Author:** ![harlandraka](https://help.nextcloud.com/letter_avatar/harlandraka/32/6_22734026db12803ebb3e059622ac3534.png) [@harlandraka](https://help.nextcloud.com/u/harlandraka)\
**Post date:** [February 16, 2017, 9:26am UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/5 "2017-02-16T09:26:16Z")

</div>

Yes, that’s what I meant! Is there a way to tell nextcloud a custom last-modified date instead of “today”? I’d like to upload all files as if they were uploaded 10 days ago, if this is possible

---

<div class="post-metadata">

**Author:** ![JasonBayton](https://help.nextcloud.com/user_avatar/help.nextcloud.com/jasonbayton/32/297_2.png) [@JasonBayton](https://help.nextcloud.com/u/JasonBayton)\
**Post date:** [February 16, 2017, 9:54am UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/6 "2017-02-16T09:54:16Z")

</div>

Not that I’m aware of. If you rsync the data you can keep last-modified dates intact on the filesystem, and Nextcloud should pick that up (I think, certainly works for media).

---

<div class="post-metadata">

**Author:** ![harlandraka](https://help.nextcloud.com/letter_avatar/harlandraka/32/6_22734026db12803ebb3e059622ac3534.png) [@harlandraka](https://help.nextcloud.com/u/harlandraka)\
**Post date:** [February 17, 2017, 8:52am UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/7 "2017-02-17T08:52:22Z")

</div>

It worked! It just take ages to rescan, but I’ve searched a bit and it seems to be due to various reasons (cache and other things).

I did a `cp -Rp` and nextcloud retained file dates, but this **didn’t work for directories** : while they have the correct timestamp on the filesystem (checked with `ls -la`), nextcloud imported them with “today” as the creation date.

Thank you!

---

<div class="post-metadata">

**Author:** ![JasonBayton](https://help.nextcloud.com/user_avatar/help.nextcloud.com/jasonbayton/32/297_2.png) [@JasonBayton](https://help.nextcloud.com/u/JasonBayton)\
**Post date:** [February 17, 2017, 9:04am UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/8 "2017-02-17T09:04:22Z")

</div>

I’ll test with rsync later. See if that happens with the archive and attributes flags.

Happy it worked 🙂

---

<div class="post-metadata">

**Author:** ![harlandraka](https://help.nextcloud.com/letter_avatar/harlandraka/32/6_22734026db12803ebb3e059622ac3534.png) [@harlandraka](https://help.nextcloud.com/u/harlandraka)\
**Post date:** [February 17, 2017, 9:15am UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/9 "2017-02-17T09:15:11Z")

</div>

Not sure if it was a nextcloud or cp issue, though. I checked with both `ls -la`, `ls -lc`, `ls -lu` and none of the timestamps displayed was actually picked up by nextcloud, it seems it picked the time it added the folder. Anyway, that’s not an issue, as I needed files to retain dates 🙂

---

<div class="post-metadata">

**Author:** ![jasit](https://help.nextcloud.com/user_avatar/help.nextcloud.com/jasit/32/15169_2.png) [@jasit](https://help.nextcloud.com/u/jasit)\
**Post date:** [February 17, 2017, 7:11pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/10 "2017-02-17T19:11:34Z")

</div>

with rsync it was a separate sync command to make sure directories have the same date after they are copied.

---

<div class="post-metadata">

**Author:** ![esbeeb](https://help.nextcloud.com/user_avatar/help.nextcloud.com/esbeeb/32/45555_2.png) [@esbeeb](https://help.nextcloud.com/u/esbeeb)\
**Post date:** [February 24, 2018, 5:21pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/11 "2018-02-24T17:21:31Z")

</div>

I’m using NextcloudPi on a Raspberry Pi (Nextcloud 13).

Here’s a few more tips which tidy up the files you’ve copied in:

After doing a giant copy of files into my Nextcloud user’s data folder (as above), I corrected the file and directory ownerships with the following (running this from the Nextcloud user’s data folder which I had just copied into):

`chown -R www-data.www-data *`

…then I cleaned up the permissions on the newly-copied files and folders like this:

```
find . -type f -print0 | xargs -0 -iHeRe chmod 644 HeRe
find . -type d -print0 | xargs -0 -iHeRe chmod 755 HeRe

```

This gives all files “-rw-r–r–” permissions, and all folders “drwxr-xr-x” permissions.

Finally I deleted any and all junk “desktop.ini” files (which Windows had annoyingly and automatically added earlier):

`find . -name "desktop.ini" -print0 | xargs -0 -iHeRe rm HeRe`

> [@harlandraka](#):
>
> - from the /path/to/nextcloud directory, run:
> 
> `sudo -u www-data php occ files:scan --user`  
> (or --all if you do this multiple times to different users)

The “scanning” command I had to do in NextcloudPi looked like this instead (note absolute pathname to “occ”, also the absense of two dashes before the Nextcloud username, which was “ncp” in my case):

`sudo -u www-data php /var/www/nextcloud/occ files:scan ncp`

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 14, 2024, 4:18pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/12 "2024-12-14T16:18:42Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 14, 2024, 4:18pm UTC](https://help.nextcloud.com/t/local-sync-with-nextcloud/8973/13 "2024-12-14T16:18:44Z")

</div>


