ZFS Appliance

From dbawiki
Jump to: navigation, search

List the sizes and available space in all filesystems on ZFS appliance[edit]

Make sure to be in the root context before running this.

script
       run('shares');
       projects = list();

       printf('%-40s %-10s %-10s\n', 'SHARE', 'USED', 'AVAILABLE');

       for (i = 0; i < projects.length; i++) {
               run('select ' + projects[i]);
               shares = list();

               for (j = 0; j < shares.length; j++) {
                       run('select ' + shares[j]);

                       share = projects[i] + '/' + shares[j];
                       used = run('get space_data').split(/\s+/)[3];
                       avail = run('get space_available').split(/\s+/)[3];

                       printf('%-40s %-10s %-10s\n', share, used, avail);
                       run('cd ..');
               }

               run('cd ..');
       }
.

and the same information but "machine readable" sizes

script
fmt = '%-40s %-15s %-15s\n';
printf(fmt, 'SHARE', 'USED', 'AVAILABLE');
run('cd /');
run('shares');
pools = choices('pool');
for (p = 0; p < pools.length; p++) {
        set('pool', pools[p]);
        projects = list();
        for (i = 0; i < projects.length; i++) {
                run('select ' + projects[i]);
                shares = list();
                for (j = 0; j < shares.length; j++) {
                        run('select ' + shares[j]);
                        share = pools[p] + ':' + projects[i] + '/' + shares[j];
                        printf(fmt, share, get('space_data'),
                            get('space_available'));
                        run('cd ..');
                }
                run('cd ..');
        }
}
.

Create a pool[edit]

[sudo] zfs create datapool mirror /dev/sdc /dev/sdd
[sudo] zfs list

Create a ZFS filesystem / dataset in the pool[edit]

[sudo] zfs create datapool/scripts -o mountpoint=/scripts

[sudo] zfs list -r datapool

Create a snapshot of the filesystem[edit]

[sudo] zfs snapshot datapool/scripts@snap1
[sudo] zfs list -t snapshot

Destroy a snapshot[edit]

[sudo] zfs destroy datapool/scripts@snap1
[sudo] zfs list -t snapshot

Rollback a snapshot[edit]

Create a file followed by a snapshot to preserve situation[edit]

[sudo] echo "hello" >/scripts/test1.txt
[sudo] cat /scripts/test1.txt
[sudo] zfs snapshot datapool/scripts@before
[sudo] zfs list -t snapshot

Change the contents of the file[edit]

[sudo] echo "goodbee" >/scripts/test1.txt
[sudo] cat /scripts/test1.txt
====Rollback to previous snapshot and see original file contents====
<pre>
[sudo] zfs list -t snapshot
[sudo] zfs rollback datapool/scripts@before
[sudo] cat /scripts/test1.txt
[sudo] zfs list -t snapshot

Rename a snapshot[edit]

[sudo] zfs rename datapool/scripts@before datapool/scripts@after
[sudo] zfs list -t snapshot

Destroy a filesystem[edit]

[sudo] zfs destroy datapool/scripts
[sudo] zfs list -r datapool

If there are snapshots of the filesystem, add -r to force the destruction

[sudo] zfs destroy -r datapool/scripts
[sudo] zfs list -t snapshot

Create a clone[edit]

Clones can only be created from a snapshot.
Snapshots cannot be deleted unless the clone is deleted.
Clone the snapshot datapool/scripts@before

[sudo] zfs clone datapool/scripts@before datapool/clone1
zfs list
ls /datapool/clone1

Attempt to destroy underlying snapshot[edit]


Attempt to destroy underlying snapshot[edit]

[sudo] zfs destroy datapool/scripts@before

Destroy clone first[edit]

[sudo] zfs destroy datapool/clone1

Attempt to destroy underlying snapshot again[edit]

[sudo] zfs destroy datapool/scripts@before