Moving directories around in Triton Object Storage (Manta)

Adam Guimont -

Introduction

Manta does not allow a "move" operation, however, you can mimic a move with SnapLinks. If you have a small number of objects to move or rename, this is achieved with the mln command. If you are reorganizing directories, you will need to create the new directory tree, link all of the objects into it, then remove the old parent directory. This article is meant to help with the latter.

Prerequisites

  • The commands in this article are for a bash shell.
    • Verify you are using bash with: echo $0
  • It is also required to have Manta CLI installed and configured for your environment.

Define the old and new directories

First, set these two variables in your terminal session:

olddir="/$MANTA_USER/stor/olddir"
newdir="/$MANTA_USER/stor/newdir"

You can leave $MANTA_USER as a variable, but update the paths to the old and new directories as needed. That is the only code you'll have to change from now on. Copy and paste the rest of the code exactly as shown.

Create the new directory tree

Parent directory

mmkdir "${newdir}"

If you need to copy role tags for the parent directory:

if minfo "${olddir}" | grep -q 'role-tag:'; then
  roles=$(minfo "${olddir}" | grep 'role-tag:' | sed 's/ //g' | cut -d':' -f2)
  mchmod -- +"${roles}" "${newdir}"
fi

Subdirectories (optional; this will also copy role tags)

If there are no subdirectories, you can skip this step.

for oldpath in $(mfind -td "${olddir}"); do
  newpath=$(echo "${oldpath}" | sed "s#${olddir}#${newdir}#")
  mmkdir "${newpath}"
  if minfo "${oldpath}" | grep -q 'role-tag:'; then
    roles=$(minfo "${oldpath}" | grep 'role-tag:' | sed 's/ //g' | cut -d':' -f2)
    mchmod -- +"${roles}" "${newpath}"
  fi
done

Create the SnapLinks

Create the lists of objects and link names, then paste them together:

mfind -to "${olddir}" > /var/tmp/olddir.txt
sed "s#${olddir}#${newdir}#" /var/tmp/olddir.txt > /var/tmp/newdir.txt
paste -d'\ ' /var/tmp/olddir.txt /var/tmp/newdir.txt > /var/tmp/mln.txt

Create the links:

while read -r line; do echo "Linking ${line}"; mln ${line}; done < /var/tmp/mln.txt

The mln command copies object role tags, so nothing extra to do there.

Remove the temporary files:

rm /var/tmp/olddir.txt /var/tmp/newdir.txt /var/tmp/mln.txt

Remove the old parent directory

mrm -r "${olddir}"

Example

$ mls ~~/stor
backup/
olddir/
test/
$ mls ~~/stor/olddir
app.py
script.js
images/
$ minfo ~~/stor/olddir | grep 'role-tag:'
role-tag: devs
$ mls ~~/stor/olddir/images
image_0.png
image_1.png
image_2.png
image_3.png
image_4.png
image_5.png
image_6.png
image_7.png
image_8.png
image_9.png
thumbs/
$ minfo ~~/stor/olddir/images/thumbs/image_3_thumb.png | grep 'role-tag:'
role-tag: devs, app

After working through the commands in this article:

$ mls ~~/stor
backup/
newdir/
test/
$ mls ~~/stor/newdir
app.py
script.js
images/
$ minfo ~~/stor/newdir | grep 'role-tag:'
role-tag: devs
$ mls ~~/stor/newdir/images
image_0.png
image_1.png
image_2.png
image_3.png
image_4.png
image_5.png
image_6.png
image_7.png
image_8.png
image_9.png
thumbs/
$ minfo ~~/stor/newdir/images/thumbs/image_3_thumb.png | grep 'role-tag:'
role-tag: devs, app

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.