Paso 1: Versionamiento de datos#
Ultima modificación: Mayo 14, 2022
Este es un proyecto que desarrolla en varios pasos
Limpieza del área de trabajo#
[1]:
!rm -rf dvcdemo dvcstore
Instalación#
La instalación se realiza usando pip
:
pip install dvc
Creación de una carpeta temporal para el demo#
[2]:
!mkdir dvcdemo
%cd dvcdemo
/workspace/dvcdemo
Inicializacion de git#
[3]:
!git init
!git config user.email jdvelasq@unal.edu.co
!git config user.name jdvelasq
Initialized empty Git repository in /workspace/dvcdemo/.git/
Inicialización de DVC#
[4]:
!dvc init
Initialized DVC repository.
You can now commit the changes to git.
+---------------------------------------------------------------------+
| |
| DVC has enabled anonymous aggregate usage analytics. |
| Read the analytics documentation (and how to opt-out) here: |
| <https://dvc.org/doc/user-guide/analytics> |
| |
+---------------------------------------------------------------------+
What's next?
------------
- Check out the documentation: <https://dvc.org/doc>
- Get help and share ideas: <https://dvc.org/chat>
- Star us on GitHub: <https://github.com/iterative/dvc>
Chequeo de la inicialización#
[5]:
!git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .dvc/.gitignore
new file: .dvc/config
new file: .dvcignore
[6]:
#
# Note que en la inicialización se agregaron los archivos
#
# .dvc/.gitignore
# .dvc/config
# .dvcignore
#
# pero seran ignorados por ahora.
#
!ls -al
total 4
drwxr-xr-x 5 root root 160 Jun 7 16:36 .
drwxr-xr-x 8 root root 256 Jun 7 16:36 ..
drwxr-xr-x 5 root root 160 Jun 7 16:36 .dvc
-rw-r--r-- 1 root root 139 Jun 7 16:36 .dvcignore
drwxr-xr-x 11 root root 352 Jun 7 16:36 .git
Configuración del remoto para almacenar las versiones de los datos#
[7]:
#
# Opciones del comando remote
#
!dvc remote --help
usage: dvc remote [-h] [-q | -v] {add,default,modify,list,remove,rename} ...
Set up and manage data remotes.
Documentation: <https://man.dvc.org/remote>
positional arguments:
{add,default,modify,list,remove,rename}
Use `dvc remote CMD --help` for command-specific help.
add Add a new data remote.
default Set/unset the default data remote.
modify Modify the configuration of a data remote.
list List all available data remotes.
remove Remove a data remote.
rename Rename a DVC remote
optional arguments:
-h, --help show this help message and exit
-q, --quiet Be quiet.
-v, --verbose Be verbose.
[8]:
#
# Almacenamiento en una carpeta local
#
!dvc remote add --default myremote dvcstore
Setting 'myremote' as a default remote.
[9]:
#
# Listado de los remotos existentes
#
!dvc remote list
myremote /workspace/dvcdemo/.dvc/../dvcstore
[10]:
#
# Se almacena la nueva configuración
#
!git commit .dvc/config -m "Initialize DVC"
!git tag -a "initialize" -m "Initialize"
[master (root-commit) 855072c] Initialize DVC
1 file changed, 4 insertions(+)
create mode 100644 .dvc/config
Creación de la carpeta local de datos#
[11]:
!mkdir -p data
!ls -l
total 0
drwxr-xr-x 2 root root 64 Jun 7 16:36 data
Búsqueda de archivos o directorios#
[12]:
repo = "https://github.com/iterative/dataset-registry"
src = "get-started/data.xml"
!dvc list {repo} {src}
data.xml
Descarga los datos desde el repositorio de ejemplo de dvc#
[13]:
dst = "data/data.xml"
!dvc get {repo} {src} -o {dst}
[14]:
#
# Contenido de la carpeta de datos
#
!ls -lh data
total 15M
-rw-r--r-- 1 root root 14M Jun 7 16:37 data.xml
Seguimiento de cambios en los datos#
[15]:
!dvc add --help
usage: dvc add [-h] [-q | -v] [-R] [--no-commit] [--external] [--glob]
[--file <filename>] [-o <path>] [--to-remote] [-r <name>]
[-j <number>] [--desc <text>]
targets [targets ...]
Track data files or directories with DVC.
Documentation: <https://man.dvc.org/add>
positional arguments:
targets Input files/directories to add.
optional arguments:
-h, --help show this help message and exit
-q, --quiet Be quiet.
-v, --verbose Be verbose.
-R, --recursive Recursively add files under directory targets.
--no-commit Don't put files/directories into cache.
--external Allow targets that are outside of the DVC repository.
--glob Allows targets containing shell-style wildcards.
--file <filename> Specify name of the .dvc file this command will
generate.
-o <path>, --out <path>
Destination path to put files to.
--to-remote Download it directly to the remote
-r <name>, --remote <name>
Remote storage to download to
-j <number>, --jobs <number>
Only used along with '--to-remote'. Number of jobs to
run simultaneously when pushing data to remote.The
default value is 4 * cpu_count().
--desc <text> User description of the data (optional). This doesn't
affect any DVC operations.
[16]:
#
# Se inicia el tracking del archivo
#
!dvc add --quiet data/data.xml
⠙ Checking graphph
[17]:
#
# Contenido de la carpeta
#
!ls -lh data/
total 14M
-rw-r--r-- 1 root root 14M Jun 7 16:38 data.xml
-rw-r--r-- 1 root root 80 Jun 7 16:38 data.xml.dvc
[18]:
#
# Archivo de tracking
#
!cat data/data.xml.dvc
outs:
- md5: 22a1a2931c8370d3aeedd7183606fd7f
size: 14445097
path: data.xml
[19]:
#
# Se adiciona el tracking de los cambios como tal.
#
!git add data/data.xml.dvc data/.gitignore
!git commit -m "Add raw data"
!git tag -a "v0" -m "raw data"
[master eacfb96] Add raw data
4 files changed, 11 insertions(+)
create mode 100644 .dvc/.gitignore
create mode 100644 .dvcignore
create mode 100644 data/.gitignore
create mode 100644 data/data.xml.dvc
Almacenamiento de datos en el remoto#
[20]:
#
# Se almacenan la versión actual de los datos en el remoto
#
!dvc push --quiet
Recuperación#
[21]:
#
# Se borran los datos existentes
#
!rm -rf .dvc/cache
!rm -f data/data.xml
#
# Se recuperan los datos
#
!dvc pull --quiet
[22]:
!ls -lh data/
total 14M
-rw-r--r-- 1 root root 14M Jun 7 16:38 data.xml
-rw-r--r-- 1 root root 80 Jun 7 16:38 data.xml.dvc
Cambios en los datos#
[23]:
#
# Simulación de más datos.
# Se duplican los datos originales.
#
!cp data/data.xml /tmp/data.xml
!cat /tmp/data.xml >> data/data.xml
[24]:
!ls -lh data/
total 28M
-rw-r--r-- 1 root root 28M Jun 7 16:38 data.xml
-rw-r--r-- 1 root root 80 Jun 7 16:38 data.xml.dvc
[25]:
#
# Se adicionan los datos al tracking
#
!dvc add --quiet data/data.xml
⠋ Checking graph
[26]:
!git commit data/data.xml.dvc -m "augmented data"
!git tag -a "v1" -m "augmented data"
[master 96d12d8] augmented data
1 file changed, 2 insertions(+), 2 deletions(-)
[27]:
!dvc push --quiet
Cambios entre versiones de los datos#
[28]:
#
# Versión anterior de los datos
#
!git checkout v0 data/data.xml.dvc
Updated 1 path from f93a129
[29]:
!ls -lh data/
total 28M
-rw-r--r-- 1 root root 28M Jun 7 16:38 data.xml
-rw-r--r-- 1 root root 80 Jun 7 16:39 data.xml.dvc
[30]:
!git commit data/data.xml.dvc -m "Revert dataset updates"
[master 2cd42eb] Revert dataset updates
1 file changed, 2 insertions(+), 2 deletions(-)