Skip to content

Examples and exercises

Yoann Valeri edited this page Mar 15, 2023 · 9 revisions

In this page we will present a tutorial and exercises on how to use Phobos. The content of this page comes from the following PDF made by Guillaume Courrier and Sebastien Gougeaud: Phobos tutorial and exercises.pdf.

Before the Advanced commands section, run the script given at the end of this page. It will setup the databases so that you can complete the exercises of the section.

Phobos tutorial

This document has been written and tested with Phobos 1.94.1. It assumes that the reader has access to a VM with Phobos installed and QuadstorVTL to manage tapes. Each exercise assumes that the previous ones were done.

Basic commands

Setup

Before we can use Phobos, we need to setup the database. Phobos provides a tool phobos_db for this purpose:

sudo -u postgres phobos_db setup_db

You will be asked to input a password for the database access. This password should match the one in the configuration /etc/phobos.conf. The option connect_string contains the information necessary for the connection to the PostgreSQL database. Make sure that the password matches as well as the host which should be localhost for this tutorial.

Once the database is setup, we can initialize the tables:

sudo phobos_db setup_tables

We can see that everything is setup properly by listing the objects in the database:

phobos object list

Since the database is empty, we should not see any output. If the command fails, the database is not properly setup.

Managing Phobos resources

Before we can write data, we need to have somewhere to write. In Phobos, that somewhere is referred to as a medium. A medium can only be accessed though a device.

Phobos can manage three types of resources (i.e. medium):

  • dir, any POSIX filesystem;
  • tape, magnetic tapes inside a library;
  • rados_pool, a pool of RADOS objects inside a Ceph cluster.

In this tutorial, we will not use RADOS pools since their management is very similar to POSIX directories and require some knowledge of Ceph.

POSIX Directories

The goal now is to write a file in a directory. For that, we want to execute the following command:

phobos put /etc/hosts my_first_object
  1. Execute the command above.
  2. What error message did you get? Why?
  3. What process do you need to start?
  4. Does the command above work now?
  5. Where can the object be written in the current setup? Try to list all the medium currently available to Phobos.
  6. What command allows you to manage POSIX directories? List all the available actions on POSIX directories.
  7. In what state should a medium be in order to be written to?
  8. Use the appropriate commands to setup a directory named /tmp/archive.
  9. Does the put command work now? If not, which option of phobos put should you use to specify where the object should be written?
  10. Open Phobos' configuration /etc/phobos.conf. Which option can you modify to write objects on directories by default? Try to put an object without the command line option.
  11. Try to list all the information about the object written.
  12. Read the content of the object into a file.
  13. Given the output of phobos extent list -o all, try to find where the object was written in /tmp/archive. You can compare the content of the file to the original file.
  14. Write an object with the metadata foo=bar. How can you list the metadata of this object ? List objects with the metadata foo=bar.

Linear Tapes

We will now do the same thing but on tape. At this point, you should have Phobos properly setup for writing to a directory. You will learn how to setup tapes in this section.

  1. What physical element do you need to write data on tape?
  2. To what Phobos command do they correspond to? List all the available options for these commands.
  3. Using lsscsi, list all the available tape drives and their LTO generation.
  4. Using mtx, list all the available drives and tapes
  5. Using mtx, load a tape into a drive. Can you load an LTO5 tape into an LTO6 drive? An LTO6 tape into an LTO5 drive?
  6. Add a drive to Phobos using the SCSI Tape device path. You can also try with the serial number (see tapeinfo).
  7. Add a tape to Phobos compatible with the drive.
  8. Try to format the tape. If this didn't work, in which state should the drive be?
  9. Can you write an object on the tape now?
  10. Check the state of the drive using mtx.
  11. Repeat steps 11 and 12 from the previous exercise.
  12. What do the fields displayed by phobos drive status mean?
  13. Using the commands mtx, lsscsi and tapeinfo, try to find the information given by phobos drive status.
  14. Given the output of phobos extent list -o all, where is the object written?
  15. Use phobos mput to write several objects in one command line.

Inspecting the state of the database

  1. Connect to the Phobos database: psql phobos phobos.
  2. List all the tables: \d.
  3. Which table contains the path to the data of an object on the medium?
  4. How does Phobos know where an object should be accessed?
  5. What is the use of the lock table?
  6. What devices are stored in the database?
  7. What media are stored in the database?
  8. List which phobos command lists the content of each table.

If you try now, you will see that it fails because it cannot contact phobosd:

<ERROR> Cannot contact 'phobosd': will abort: Transport endpoint is not connected

This is because, phobos cannot manage the media and devices directly. This needs to be done by a central component: phobosd.

systemctl start phobosd

The daemon should be up and running. Use phobos ping to see if it is able to accept new requests.

If you try the phobos put command again, it will still not work but for a different reason: No space left on device. This error was sent by the daemon because it currently have no medium on which it can write data. Hence, no space left on device.

So if we want to write data, we need to add a directory to Phobos:

mkdir /tmp/archive
phobos dir add /tmp/archive

Once added, we can see the information inside the database:

phobos dir list -o all
/tmp/archive

Once in the database, we need to format the directory and unlock it:

phobos dir format /tmp/archive
phobos dir unlock /tmp/archive

The phobos put command will now work.

You can read back the data and check if the retrieved file match:

phobos get my_first_object /tmp/out
diff /etc/hosts /tmp/out

We can also see our first object in the database:

phobos object list -o all

Advanced commands

Before going through this section, remember to run the script at the end of this page to setup each database beforehand, as we will ask you to switch database

Labelling media

In your configuration file, change the dbname to phobos21, then restart the phobosd and:

  1. Create then add to the database a set of 10 directories such as:
  • they are named tuto{1..10};
  • the first two get the tag cache;
  • the last five get the tag archive;
  • the last two also get the tag read-only.
  1. Format all the directories and unlock only the directories 1, 3 and 7.
  2. Try to launch the following commands, and tell why some of them fail:
phobos put /etc/hosts tuto1
phobos put --tags cache /etc/hosts tuto2
phobos put --tags archive /etc/hosts tuto3
phobos put --tags read-only /etc/hosts tuto4
phobos put --tags archive,read-only /etc/hosts tuto5
  1. After unlocking the directory 9, does the fifth command succeed?

Updating labels

In your configuration file, change the dbname to phobos22, then restart the phobosd and:

  1. List the available tapes.
  2. Update the tapes tags such as:
  • tag old-gen on LTO7 tapes;
  • tag to-format on tapes tagged as corrupted.
  1. Check the tags update succeed.

Updating access

In your configuration file, change the dbname to phobos23, then restart the phobosd and:

  1. Modify the directory accesses such as:
  • we can write on the directory tagged fast;
  • we can retrieve the object tuto1;
  • we can delete the object tuto2.
  1. Remove all the accesses of all directories.

Locating resources

In your configuration file, change the dbname to phobos24, then restart the phobosd and:

  1. List the available tapes and directories.
  2. For each of them, launch a locate command and tell why the command gives you this result.
  3. What will happen if a get command target an object located on the xxxx tape?

Locating objets

In your configuration file, change the dbname to phobos24 (if not already done), then restart the phobosd and:

  1. List the objects.
  2. For each of them, launch a locate command and tell why the command gives you this result.
  3. What will happen if a get command target the object on-distant-dir? The object on-both-tapes?

Updating an object

In your configuration file, change the dbname to phobos25, then restart the phobosd and:

  1. List the objects.
  2. Update the object to-update by pushing the file /etc/hosts.
  3. List the deprecated versions using the option --deprecated to check if the overwritten version still exists.
  4. Retrieve the version 1 of the object to-update.

Adding and deleting objets

In your configuration file, change the dbname to phobos26, then restart the phobosd and:

  1. Create and add one directory to the Phobos system. Format and unlock it.
  2. Add an objet to the system.
  3. Delete it using the del command.
  4. List the deleted object using the option --deprecated.
  5. Cancel the deletion.
  6. Check the object is alive using the list command.

Managing objects

In your configuration file, change the dbname to phobos26 (if not already done), then restart the phobosd and:

  1. List the objects.
  2. Delete the object to-remove.
  3. List the deleted/deprecated objects.
  4. Cancel the deletion of the objects removed2 and removed3.
  5. Why the operation did not work for removed3? % removed3 doit générer une erreur, car existant déjà
  6. Retrieve the contents of removed3 and insert it back in the system.

Managing aliases

In your configuration file, change the dbname to phobos27, then restart the phobosd and:

  1. Before launching phobosd, open the configuration file and look at the definition of the default alias.
  2. Define two new aliases:
  • fast-archive -- 1 replica, using fast tagged tapes;
  • mirror-cache -- 3 replicas, using directories.
  1. Add two objects to the Phobos system, one for each alias.
  2. Check the alias was well-considered, by listing the extents.
  3. Repeat the last two questions with the following parameters, without defining an alias: 2 replicas, on raid tagged directories.

Advanced commands script

Here is the script that should be run before the Advanced commands section:

#!/usr/bin/sh

DATABASES=(phobos21 phobos22 phobos23 phobos24 phobos26 phobos27 phobos28 phobos29)
for db in "${DATABASES[@]}"; do
    sudo -u postgres phobos_db setup_db -d $db -s -p phobos
done

# phobos22
sed -i s/dbname=phobos/dbname=phobos22/g /etc/phobos.conf
phobos tape add -t lto7 P0000[0-7]L7
phobos tape add -t lto8 P0000[0-7]L8
phobos tape update -T corrupted P0000[3-4]L7 P0000[6-7]L8

# phobos23
sed -i s/dbname=phobos22/dbname=phobos23/g /etc/phobos.conf
systemctl start phobosd
DIRS="/mnt/23/aries /mnt/23/taurus /mnt/23/gemini"
mkdir -p $DIRS
phobos dir add $DIRS
phobos dir format --unlock $DIRS
phobos dir update -T fast /mnt/23/taurus
phobos dir update -T t1 /mnt/23/gemini
phobos dir update -T t2 /mnt/23/aries
echo "tuto 1" > tuto1
echo "tuto 2" > tuto2
phobos put -f dir --tags t1 tuto1 tuto1
phobos put -f dir --tags t2 tuto2 tuto2
phobos dir update -T "" /mnt/23/aries /mnt/23/gemini
phobos dir set-access -- -PGD $DIRS
systemctl stop phobosd
rm -f tuto1 tuto2
unset DIRS

# phobos24
sed -i s/dbname=phobos23/dbname=phobos24/g /etc/phobos.conf
DIRS="/mnt/24/aries /mnt/24/taurus"
mkdir -p $DIRS
psql phobos24 phobos -c "insert into device (family,id,host,adm_status,path) values ('dir','vm0:/mnt/24/aries','vm0','unlocked','/mnt/24/aries'), ('dir','vm0:/mnt/24/taurus','vm0','unlocked','/mnt/24/taurus'), ('dir','vm1:/mnt/24/gemini','vm1','unlocked','/mnt/24/gemini');"
psql phobos24 phobos -c "insert into media (family,id,adm_status,fs_type,fs_label,address_type,fs_status,stats,tags,put,get,delete) values ('dir','/mnt/24/aries','unlocked','POSIX','/mnt/24/aries','HASH1','empty','{\"nb_obj\":0,\"last_load\":0,\"nb_errors\":0,\"logc_spc_used\":0,\"phys_spc_free\":10271260672,\"phys_spc_used\":0}','[]','t','t','t'), ('dir','/mnt/24/taurus','unlocked','POSIX','/mnt/24/taurus','HASH1','empty','{\"nb_obj\":0,\"last_load\":0,\"nb_errors\":0,\"logc_spc_used\":0,\"phys_spc_free\":10271260672,\"phys_spc_used\":0}','[]','t','t','t'), ('dir','/mnt/24/gemini','unlocked','POSIX','/mnt/24/gemini','HASH1','empty','{\"nb_obj\":0,\"last_load\":0,\"nb_errors\":0,\"logc_spc_used\":0,\"phys_spc_free\":10271260672,\"phys_spc_used\":0}','[]','t','t','t');"
psql phobos24 phobos -c "insert into lock (type,id,hostname,owner) values ('device','vm0:/mnt/24/aries','vm0','1234'),('device','vm0:/mnt/24/taurus','vm0','1234'),('device','vm1:/mnt/24/gemini','vm1','1234'),('media','/mnt/24/aries','vm0','1234'),('media','/mnt/24/taurus','vm0','1234'),('media','/mnt/24/gemini','vm1','1234');"
psql phobos24 phobos -c "insert into media (family,model,id,adm_status,fs_type,fs_label,address_type,fs_status,stats,tags,put,get,delete) values ('tape','LTO7','P00000L7','unlocked','LTFS','P00000L7','HASH1','empty','{\"nb_obj\":0,\"last_load\":0,\"nb_errors\":0,\"logc_spc_used\":0,\"phys_spc_free\":1581621706752,\"phys_spc_used\":0}','[]','t','t','t'),('tape','LTO7','P00001L7','unlocked','LTFS','P00001L7','HASH1','empty','{\"nb_obj\":0,\"last_load\":0,\"nb_errors\":0,\"logc_spc_used\":0,\"phys_spc_free\":1581621706752,\"phys_spc_used\":0}','[]','t','t','t'),('tape','LTO7','P00002L7','unlocked','LTFS','P00002L7','HASH1','empty','{\"nb_obj\":0,\"last_load\":0,\"nb_errors\":0,\"logc_spc_used\":0,\"phys_spc_free\":1581621706752,\"phys_spc_used\":0}','[]','t','t','t');"
psql phobos24 phobos -c "insert into lock (type,id,hostname,owner) values ('media','P00000L7','vm0','1234'),('media','P00001L7','vm1','1234');"
psql phobos24 phobos -c "insert into object (oid,user_md,uuid) values ('where-is-the-tape','{}','d63747d0-0abf-49ae-b71f-eaa8464c2832'), ('copied-on-both-hosts','{}','6218280a-c955-455e-9679-02a4132317b0'), ('split-on-both-hosts','{}','bf89faaa-31b9-4b61-a0fa-0f2e497d87e5'),('on-both-tapes','{}','399d5d2e-8cfe-48bf-8e56-378d49b472d8'),('on-distant-dir','{}','5c85a0a4-e44b-4692-a234-2de38b683abd');"
psql phobos24 phobos -c "insert into extent (oid,uuid,version,state,lyt_info,extents) values ('copied-on-both-hosts','6218280a-c955-455e-9679-02a4132317b0','1','sync','{\"name\":\"raid1\",\"attrs\":{\"repl_count\":\"2\"},\"major\":0,\"minor\":2}','[{\"sz\":97158,\"fam\":\"dir\",\"addr\":\"e4/be/copied-on-both-hosts.1.r1-2_0.6218280a-c955-455e-9679-02a4132317b0\",\"media\":\"/mnt/24/taurus\"},{\"sz\":97158,\"fam\":\"dir\",\"addr\":\"d5/33/copied-on-both-hosts.1.r1-2_1.6218280a-c955-455e-9679-02a4132317b0\",\"media\":\"/mnt/24/gemini\"}]'),('where-is-the-tape','d63747d0-0abf-49ae-b71f-eaa8464c2832','1','sync','{\"name\":\"raid1\",\"attrs\":{\"repl_count\":\"1\"},\"major\":0,\"minor\":2}','[{\"sz\":97158,\"fam\":\"tape\",\"addr\":\"77/c6/where-is-the-tape.1.r1-1_0.d63747d0-0abf-49ae-b71f-eaa8464c2832\",\"media\":\"P00002L7\"}]'),('split-on-both-hosts','bf89faaa-31b9-4b61-a0fa-0f2e497d87e5','1','sync','{\"name\": \"raid1\", \"attrs\": {\"repl_count\": \"1\"}, \"major\": 0, \"minor\": 2}','[{\"sz\": 1024, \"fam\": \"dir\", \"addr\": \"98/65/split-on-both-hosts.1.r1-1_0.bf89faaa-31b9-4b61-a0fa-0f2e497d87e5\", \"media\": \"/mnt/24/gemini\"}, {\"sz\": 1024, \"fam\": \"dir\", \"addr\": \"98/65/split-on-both-hosts.1.r1-1_0.bf89faaa-31b9-4b61-a0fa-0f2e497d87e5\", \"media\": \"/mnt/24/taurus\"}]'),('on-both-tapes','399d5d2e-8cfe-48bf-8e56-378d49b472d8','1','sync','{\"name\":\"raid1\",\"attrs\":{\"repl_count\":\"1\"},\"major\":0,\"minor\":2}','[{\"sz\":1024,\"fam\":\"tape\",\"addr\":\"54/b9/on-both-tapes.1.r1-1_0.399d5d2e-8cfe-48bf-8e56-378d49b472d8\",\"media\":\"P00000L7\"},{\"sz\":1024,\"fam\":\"tape\",\"addr\":\"54/b9/on-both-tapes.1.r1-1_0.399d5d2e-8cfe-48bf-8e56-378d49b472d8\",\"media\":\"P00001L7\"}]'),('on-distant-dir','5c85a0a4-e44b-4692-a234-2de38b683abd','1','sync','{\"name\":\"raid1\",\"attrs\":{\"repl_count\":\"1\"},\"major\":0,\"minor\":2}','[{\"sz\":1024,\"fam\":\"dir\",\"addr\":\"4e/cf/on-distant-dir.1.r1-1_0.5c85a0a4-e44b-4692-a234-2de38b683abd\",\"media\":\"/mnt/24/gemini\"}]');"
psql phobos24 phobos -c "insert into device (family,model,id,host,adm_status,path) values ('tape','ULT3590-TD7','0123456789','vm0','unlocked','/dev/24/st0');"
psql phobos24 phobos -c "insert into lock (type,id,hostname,owner) values ('device','vm0:/dev/24/st0','vm0','1234');"
unset DIRS

# phobos26
sed -i s/dbname=phobos24/dbname=phobos26/g /etc/phobos.conf
systemctl start phobosd
DIR="/mnt/26/aries"
mkdir -p $DIR
phobos dir add $DIR
phobos dir format --unlock $DIR
echo "version 1" > v1
echo "version 2" > v2
echo "told you so\!" > un
phobos put --family dir v1 to-update
phobos put --family dir un useless
phobos put --family dir --overwrite v2 to-update
phobos put --family dir un dont-try
rm -f v1 v2 un
systemctl stop phobosd
unset DIR

# phobos28
sed -i s/dbname=phobos26/dbname=phobos28/g /etc/phobos.conf
systemctl start phobosd
DIR="/mnt/28/aries"
mkdir -p $DIR
phobos dir add $DIR
phobos dir format --unlock $DIR
echo "just joking" > us
echo "was deleted" > del
echo "need to be removed" > rem
phobos put --family dir del removed2
phobos put --family dir del removed3
phobos delete removed2 removed3
phobos put --family dir us removed3
phobos put --family dir rem to-remove
rm -f us del rem
systemctl stop phobosd
unset DIR

sed -i s/dbname=phobos28/dbname=phobos/g /etc/phobos.conf