0

I'm trying to set up a cron job to create a btrfs subvolume snapshot of my root partition. The command works perfectly if I run it from the command line, but nothing happens at the scheduled cron time. I've tried piping to logger and redirecting stdout/stderr to file, and not only is there no content, the file I'm logging to isn't even created.

The cron command I have is as follows:

0 0 * * * /sbin/btrfs subvolume snapshot / "/snapshots/$(date +%Y-%m-%d)"

I've tried prefixing it with /bin/bash, but that makes no difference. What am I missing?

2
  • Are you sure that cron is running? Check the output of ls -l | grep cron for something like /usr/bin/crond. If your only process showing is grep cron or perhaps grep --color=auto cron then it isn't. You'll need to start the cron server via whatever method it is your disto has for managing servers. service cron start works on a number of popular distros.
    – 0xDAFACADE
    Commented Aug 16, 2014 at 3:31
  • Yes, cron is running, although ls -l | grep cron isn't the command to tell me that. pgrep cron returned a PID. I also added a job * * * * * touch /root/foo, which worked as expected.
    – Mikkel
    Commented Aug 16, 2014 at 19:17

1 Answer 1

0

I never did figure out what was wrong with the cron entry, but I just wrote a shell script to create the snapshot and invoked that from cron instead.

#!/usr/bin/env bash
/sbin/btrfs subvolume snapshot / "/snapshots/$(date +%Y-%m-%d)"
touch  "/snapshots/$(date +%Y-%m-%d)"
find /snapshots/* -maxdepth 0 -mtime +6 | xargs -n 1 /sbin/btrfs subvolume delete

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .