There may be situations where you'd like to keep your content sets protected with AutoGraph watermarking only for a certain period of time (e.g. because you publish the content after some time also via other channels where it cannot be protected anymore anyway, like for example DVD releases or tube sites).

In such cases you can set up a cron job on your server that runs our automatic clean-up script which allows automating the process of rotating older video content sets off the our watermarking service and deleting them from our storage. This can be useful also for reducing costs by only protecting your most recent content.


The script performs two main actions:

1.  Rotates off old content: It renames the `.htaccess` file within content set folders that are older than a specified cutoff date. This stops the content from being served through our watermarking CDN service and instead serves it from your own server (or alternative CDN).
2.  Deletes old data: It then communicates with our API to permanently delete the video data associated with those rotated sets from our storage systems, freeing up your storage quota.

Important Note: Once data is deleted from our systems, it is no longer possible to trace pirated copies of that content.


Setting it up

Step 1: Configure the Script

Before setting up the cron job, the script must be properly configured with your API credentials and desired cutoff age.

  1. Open the script file (xvidcleanupoldsets.php) in a text editor.
  2. Locate the configuration section at the top of the script. It will look something like this:
    // --- CONFIGURATION ---
    $client_id = 'YOUR_CLIENT_ID_HERE'; // Replace with your client_id
    $client_secret = 'YOUR_CLIENT_SECRET_HERE'; // Replace with your client_secret
    $cutoff_age = 365 * 24 * 3600; // Age in seconds (default: 1 year)
    // ---------------------
    
  3. Fill in your credentials:
    • Find your client_id and client_secret in your site's configuration file, typically located at /home/httpd/html/YOUR_SITE/public_html/members/cmsinclude.ini.php.
      Look for the APP_CLIENT_ID and APP_CLIENT_SECRET variables.
    • Copy and paste these values into the $client_id and $client_secret variables in the script.
  4. Set the cutoff age:
    • The $cutoff_age variable determines how old (in seconds) a content set must be before it is rotated off the service. The default is one year (365 * 24 * 3600).
    • Best Practice: It is highly recommended to start with a longer period (e.g., 2 years) for the first test to ensure everything works as expected before shortening it to your desired timeframe.
  5. Save the script:
    • Put the script somewhere outside your site's html root, e.g.: /home/httpd/html/YOUR_SITE/scripts/xvidcleanupoldsets.php
    • Make sure the script has the executable bit set (chmod +x) and its permissions/ownership allow your webserver user to run it.

Step 2: Test the Script Manually

This is an important step to verify that the script works, is correctly configured and runs with the correct user permissions.

  1. Log in to your server via SSH.

  2. Switch to the webserver user. This is crucial to ensure the script has the same permissions as your web server. The user is often apache, httpd, nobody, or similar. You can find this by checking your web server's configuration or by asking your host. For this example, we'll assume the user is apache.

    sudo su - apache
  3. Navigate to the directory where the script is located.

  4. Run the script with the correct parameter. The parameter is the absolute path to your site's content/upload folder.

    php -f /path/to/your/script/xvidcleanupoldsets.php /home/httpd/html/YOUR_SITE/public_html/members/content/upload/

    Replace /path/to/your/script/ with the actual path where you placed the script file.

  5. Verify the output. A successful run will produce output similar to this:

    [Date and Time] Renamed: /path/to/content/set1/.htaccess
    [Date and Time] Renamed: /path/to/content/set2/.htaccess
    {"result":{"status":"SUCCESS"}}[Date and Time] Deleted: /path/to/content/set/1/.htaccess_delete_me|...
    {"result":{"status":"SUCCESS"}}[Date and Time] Deleted: /path/to/content/set/2/.htaccess_delete_me|...

    If you see any errors, especially ERROR: Failed to obtain API access token, the script is not configured correctly. Go back and double-check your credentials in Step 1.

Step 3: Set Up the Cron Job

Once the manual test is successful, you can set up the cron job. The cron job must be configured to run as the same webserver user (e.g. apache) that you used in the manual test.

  1. Edit the root crontab. This allows you to specify which user the command should run as.

    sudo crontab -e
  2. Add the following line to the crontab file. This example runs the script daily at 11 PM.

    0 23 * * * apache /usr/local/bin/php -f /path/to/your/script/xvidcleanupoldsets.php /home/httpd/html/YOUR_SITE/public_html/members/content/upload/

    Breakdown of this line:

    • 0 23 * * *: This is the schedule. It means "at minute 0 of hour 23 (11 PM), every day, every month, every day of the week."
    • apache: This is the critical part. It specifies that the command should be run as the apache user. This ensures the script has the correct file permissions and avoids issues with file ownership.
    • /usr/local/bin/php: The path to the PHP executable. (Confirm this path with your host if you are unsure).
    • -f /path/to/your/script/...: The command to execute.
  3. Save and exit the editor.

Step 4: Verify the Cron Job is Running

  1. Check the cron logs. The easiest way is to look at the system logs.

    grep CRON /var/log/syslog

    You should see entries showing that the cron job was scheduled.

  2. Check for script output. The best practice is to redirect all output to a log file. You can modify your crontab entry to do this, e.g.:

    0 23 * * * apache /usr/local/bin/php -f /path/to/your/script/xvidcleanupoldsets.php /home/httpd/html/YOUR_SITE/public_html/members/content/upload/ >> /home/httpd/html/YOUR_SITE/public_html/cms_admin/xvid/xvid_cron.log 2>&1

    This will append both standard output and errors to the xvid_cron.log file. You can monitor this file to see the script's activity and confirm it's working as expected.

Key Considerations for Multiple Sites

If you manage multiple sites on the same server, you will need to perform these steps for each site individually. The script is designed to run on a per-site basis.

  1. Place a copy of the script in a suitable location for each site (or use a shared location if permissions allow).
  2. For each site, you must create a separate cron job entry in the crontab.
  3. Each cron job entry must specify the correct content/upload path for that specific site and be run under the correct webserver user (if webserver users are different).


  • No labels