Lompat ke konten

Pelajaran 6 ยท Remote Storage

DVC Remotes: Share Data with push and pull

Set up a DVC remote, choose a default, upload and download data with push, pull and fetch, check what is missing with status, and avoid broken team history.

Your cache lives on one computer. A remote is a shared storage location where DVC copies cache objects so that teammates, servers and your future self can get them. It plays the same role for data that a Git remote plays for code, but the two are separate.

Add a remote

The simplest remote is a folder, for example on a network drive or a second disk. It is perfect for practice.

Terminal
# Read-only: a local folder as the default remote
dvc remote add -d storage /srv/dvc-storage
git add .dvc/config
git commit -m "Configure DVC remote"

storage is a name you choose. The -d flag makes it the default. The command writes to .dvc/config, which you commit so teammates see the same remote. DVC infers the storage type from the URL: a plain path means local storage, and prefixes such as s3:// or ssh:// select other backends.

Other management commands:

Command Purpose
dvc remote list Show configured remotes
dvc remote default <name> Change or show the default
dvc remote modify <name> <option> <value> Set options
dvc remote rename <old> <new> Rename a remote
dvc remote remove <name> Delete the configuration (not the stored data)

Push, pull and fetch

Terminal
# Read-only: the main transfer commands
dvc push        # upload objects the remote is missing
dvc pull        # download objects and place them in the workspace
dvc fetch       # download into the cache only

dvc pull is roughly dvc fetch followed by dvc checkout. Fetch is useful when you want the data ready in the cache without changing any file yet.

DVC transfers only what is missing, because objects are named by content. You can limit work to a target, such as dvc push data/reviews.csv.dvc, or pick another remote with -r name. A .dvc file or a dvc.yaml output may also name its own remote with a remote field.

By default, dvc push covers the data referenced by your current workspace. To include data from other places in history, add -a (all branches), -T (all tags) or -A (all commits). The last option can move a very large amount of data, so use it deliberately.

Order matters

Git and DVC pushes are independent. The classic team problem is a pushed commit that points to data nobody uploaded.

flowchart LR
  A["Edit data"] --> B["dvc add"]
  B --> C["git commit"]
  C --> D["dvc push"]
  D --> E["git push"]

Push the data before you push the commit that refers to it.

When a teammate sees a pull failure, a very common cause is that the author forgot dvc push. A Git pre-push hook installed by dvc install automates this step.

Check what is missing

  • dvc status -c compares your cache with the default remote and shows what still needs uploading or downloading.
  • dvc data status --not-in-remote lists tracked data that is absent from the remote.

In CI you can use checks like these to fail early when someone forgot to push (see DVC in CI).

Try the idea

This stand-in models a remote as a second dictionary. It shows why only missing objects move and what goes wrong when a push is skipped. Real DVC talks to storage services and verifies much more.

Python Stand-in: push, then pull on another machine

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Remote layout is not for humans

A DVC remote stores objects named by hash. You will not see friendly file names there, and you should not edit or reorganize the files by hand. Use DVC commands (or dvc get and dvc list, covered later) to retrieve data by its project path.

Common mistake: deleting old objects from the storage "to save money". An old Git commit may still point to them. Use dvc gc with care instead, and read Cleaning Storage and Best Practices first.

Planning your remote

Before you pick a location, answer these questions:

  • Who needs read access, and who may write or delete?
  • Is the data allowed to leave your region or company network?
  • Is there versioning or backup on the storage side, in case of mistakes?
  • What will it cost to store and download? Check your provider's current price page.

One remote per project is a fine start. You can add a second one for sensitive data and point specific outputs at it with the remote field.

A practice run

Try this loop once with a scratch folder as the remote: track a file, push, delete both the workspace file and the .dvc/cache folder in the scratch project, then run dvc pull. Seeing the file return builds real confidence in the setup. Never do this experiment on a project whose data you cannot recreate.

Speed and large transfers

Transfers run in parallel. The --jobs flag sets how many files move at once. More jobs can help with many small files, but too many may hit operating system limits or storage service limits. If you only need part of a project, name targets instead of pulling everything. For example, a testing machine might need only the test dataset and the final model. Interrupted transfers can normally be repeated: run the same command again, and DVC moves what is still missing.

Naming remotes

Pick names that describe a purpose, such as storage or restricted, not a person or a temporary machine. The name appears in .dvc/config and possibly in pointer files, so everyone on the team will read it for a long time.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the -d flag do in dvc remote add -d storage /srv/dvc-storage?

    The default remote is used by push, pull and fetch unless you name another.
  2. 2. Which command downloads objects into the cache without changing workspace files?

    Fetch fills the cache. Pull also updates the workspace.
  3. 3. A teammate cannot pull data from your latest commit. What is a very likely cause?

    Pointer files reached them, but the objects never reached the remote.
  4. 4. Which command shows tracked data that is not yet in the remote?

    It lists tracked data that the remote lacks.

Summary

  • A remote is shared storage for cache objects and is separate from your Git remote.
  • dvc remote add -d creates a default remote; commit .dvc/config.
  • push uploads, fetch downloads to cache, pull downloads and checks out.
  • Push data before pushing the commit that points to it.
  • Do not edit or delete objects in a remote by hand.

Next: Cloud Remotes and Credentials

Progres Anda disimpan di browser ini. Tidak perlu akun.