Protect Recordings From Deletion
In a multiple-user environment, you may want to be able to protect recordings from being deleted by other users. It turns out there is a very easy way to do this: User Jobs. It is possible to create a pair of User Jobs that will protect and unprotect a file, and which can be run automatically from the scheduler or interactively from the frontend.
The mythtv user needs to have the appropriate rights on every machine that processes User Jobs in order to execute these jobs. In particular, mythtv needs to be able to run /usr/bin/chattr as root, without password authentication. To accomplish this, execute "visudo" as root on each box and add this line to the file:
mythtv ALL=NOPASSWD: /usr/bin/chattr
If you already have an entry for user mythtv, you can simply append ",/usr/bin/chattr" to that entry.
How to Protect a Recording
In order to protect a recording, you need to create a User Job that meets the following parameters (in this example, we're using "User Job 1"):
- userjobdesc1: "Prevent Deletion"
- userjob1: "sudo /usr/bin/chattr +i %DIR%/%FILE%"
- joballowuserjob1: "1"
See User Jobs for methods to create a user job. It is important that every machine that runs mythjobqueue or mythbackend has the appropriate "joballowuserjob" set, and has the sudo capability described in the prerequisite section.
When this job is run, the recording will be protected from all modifications. From the "chattr" man page:
A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.
(Note that this may break other MythTV functionality. Any act that would result in the modification or deletion of the original file may not behave exactly as expected, as the file is protected from all modification.)
To protect a file from deletion, you simply run this User Job; either automatically in the recording rule, or you can interactively queue the job from the User_Manual:Watch_Recordings (press Info and go to Job Options).
How to Remove Protection from a Recording
In order to delete a protected recording, you must explicitly remove protection. Another User Job is required to accomplish this (the example uses "User Job 2"):
- userjobdesc2: "Allow Deletion"
- userjob2: "sudo /usr/bin/chattr -i %DIR%/%FILE%"
- joballowuserjob2: "1"
As with protecting a recording, all hosts that process the job queue must be able to run this job, and must have the appropriate "sudo" permissions.
Running this job will simply remove the file protection, and revert to the normal state. The procedure for queuing this job is the same as the "Prevent Deletion" job.
This article was culled from a discussion on the mythtv-users list. You can view the archived discussion  for background information or other methods to reduce the likelihood of accidental deletion of recordings.