Moving the sites directory to a ZFS dataset

@adunsulag
Years ago, when I was using UFS, I used to mount my documents directory for using openemr and unmount it for upgrading openemr. Since FreeBSD added support for ZFS, I have been using my whole drive, but upgrading openemr is very tedious because I have a multisite installation.

Today I moved my sites directory to a zfs dataset. Here is what I did. (I would like to turn this into a tutorial for the wiki, but it is incomplete.)

Firstly, do not attempt this in a production server, you may lose your data.
Second, back up your data, please!
Stop the server first, to avoid data loss.

This tutorial assumes openemr root directory is located at /www/openemr
and there is a directory for backups in /bkup

There are multiple ways to back up the sites directory. This is one method:

% sudo cd /www/openemr/sites
% sudo tar czvf /bkup/`date +"%Y%m%d:%H:%M:%S"`_www-openemr-sites.tgz .

The above commands generate a file named /bkup/20221207:19:31:06_www-openemr-sites.tgz.

Then, rename the sites directory:

% sudo cd ../
% sudo cp /www/openemr/sites /www/openemr/sites.bkup

While in the openemr directory, create a new sites directory in openemr and give the http server full ownership:

% sudo mkdir sites
% sudo chown www:www sites

Now create the zfs dataset “sites”, in my zroot pool:

% sudo zfs create zroot/sites

Now set the mount point for the dataset to your openemr installation.

% sudo zfs set mountpoint=/www/openemr/sites zroot/sites

Verify that it all worked:

% sudo zfs list | grep sites
zroot/sites                                   1.48G  1.62T     1.48G  /www/openemr/sites

To unmount the dataset:

% sudo umount zroot/sites

Now check again, zfs should not show the dataset:

% sudo zfs list | grep sites
%

To mount it again:

% sudo zfs mount zroot/sites

Now check again:

% sudo zfs list | grep sites
zroot/sites                                   1.48G  1.62T     1.48G  /www/openemr/sites

Now copy the contents of sites.bkup to the new directory, which is now a mountable dataset:

% sudo cd /www/openemr
% sudo cp -ipvr sites.bkup/ sites

Once you are sure all the contents have been copied, the old directory can be moved somewhere else.
(If this is done in a production server, it should be done at a time when openemr is not being used. Maybe shut down apache and perhaps the database to make sure no documents are lost.)

The reason for doing all this is to benefit from zfs incremental backups and to simplify upgrading openemr, particularly in multisite installs. So, when upgrading openemr, we can just unmount the dataset to protect the sites directory.

("date +"%Y%m%d:%H:%M:%S"" is used in python which is what freebsd is based on. I will need one of the ubuntu guys to help me with setting today’s date in a backup command, for the tutorial)

1 Like