计划任务备份

其他 社区

技能解读

当前原文的自动摘译,尚未人工审校。

为什么

Cron 作业配置代表着巨大的投资——时间表、有效负载、交付目标和飞行前检查都是手动调整的。错误配置的openclaw cron edit或意外删除可能会擦除该工作。此技能提供了一个安全网:您可以从中恢复的时间点快照。

脚本

scripts/cron-backup.mjs——零依赖。 Node.js 18+。

要求

Node.js 18+(使用内置 fetch、fs、path) openclaw CLI 在 PATH 中可用(适用于 openclaw cron list --json)

备份格式

每个备份都是一个 JSON 文件:导出的作业没有运行时状态(不包括state)——备份捕获配置,而不是历史记录。

导入行为

默认情况下,导入是非破坏性的:它仅恢复当前队列中缺少的作业(已删除的作业)。除非使用--force,否则不会修改现有作业。 --force:覆盖与备份不同的现有作业。在继续之前显示差异。 --dry-run:准确显示在不进行更改的情况下将添加/修改/删除的内容。导入通过openclaw cron add创建工作并通过openclaw cron edit更新。

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
通用
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@track-org · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
macOS · Linux · Windows
运行环境要求
Node.js
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
网络行为
允许外网请求
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# Cron Backup

Export and import OpenClaw cron job configurations as versioned JSON snapshots. Safe, idempotent, and designed for both manual and automated (heartbeat/cron) use.

## Why

Cron job configs represent significant investment — schedules, payloads, delivery targets, and preflight checks are all hand-tuned. A misconfigured `openclaw cron edit` or accidental delete can wipe that work. This skill provides a safety net: point-in-time snapshots you can restore from.

## Scripts

- `scripts/cron-backup.mjs` — Zero dependencies. Node.js 18+.

## Requirements

- Node.js 18+ (uses built-in `fetch`, `fs`, `path`)
- `openclaw` CLI available in PATH (for `openclaw cron list --json`)

## Usage

### Export (create a backup)

```bash
# Full fleet backup (all jobs)
node cron-backup.mjs export

# Single job by ID or name
node cron-backup.mjs export --job "Solar export WhatsApp nudge"
node cron-backup.mjs export --job 2e0eb8eb-2192-4966-b6cf-f3c0046f901b

# Custom output directory
node cron-backup.mjs export --dir /tmp/my-backups

# Limit number of rotated backups (default: 10)
node cron-backup.mjs export --max-backups 5
```

### Import (restore from backup)

```bash
# Show what would be restored (dry run)
node cron-backup.mjs import --dry-run

# Restore most recent backup
node cron-backup.mjs import

# Restore a specific backup file
node cron-backup.mjs import --file backups/cron-backup-2026-05-23T00-00-00.json

# Force restore even if current jobs match (overwrite)
node cron-backup.mjs import --force

# Restore a single job from backup
node cron-backup.mjs import --job "Solar export WhatsApp nudge"
```

### List backups

```bash
# Show all available backups
node cron-backup.mjs list

# JSON output
node cron-backup.mjs list --json
```

### Diff

```bash
# Compare current fleet vs most recent backup
node cron-backup.mjs diff

# Compare current fleet vs a specific backup
node cron-backup.mjs diff --file backups/cron-backup-2026-05-22T00-00-00.json
```

## Backup Format

Each backup is a JSON file:

```json
{
  "schema": "cron-backup-v1",
  "exportedAt": "2026-05-23T00:00:00.000Z",
  "hostname": "raspberrypi",
  "jobCount": 4,
  "jobs": [
    {
      "id": "2e0eb8eb-...",
      "name": "Solar export WhatsApp nudge",
      "description": "...",
      "enabled": true,
      "schedule": { "kind": "cron", "expr": "0,30 6-21 * * *", "tz": "Europe/Dublin" },
      "sessionTarget": "main",
      "payload": { ... },
      "delivery": { ... }
    }
  ]
}
```

Jobs are exported without runtime state (`state` is excluded) — backups capture config, not history.

## Import Behaviour

- **By default, import is non-destructive**: it only restores jobs that are missing from the current fleet (deleted jobs). Existing jobs are not modified unless `--force` is used.
- **`--force`**: overwrites existing jobs that differ from the backup. Shows a diff before proceeding.
- **`--dry-run`**: shows exactly what would be added/modified/deleted without making changes.
- Import creates jobs via `openclaw cron add` and updates via `openclaw cron edit`.

## Rotation

- Default: keeps the last 10 backups per output directory
- Older backups are automatically cleaned up on export
- Use `--max-backups` to adjust

## Flags

| Flag | Short | Default | Description |
|------|-------|---------|-------------|
| `--dir` | `-d` | `./backups` | Backup directory path |
| `--file` | `-f` | *(latest)* | Specific backup file to import/diff |
| `--job` | `-j` | *(all)* | Single job name or ID |
| `--max-backups` | `-m` | 10 | Max rotated backups to keep |
| `--dry-run` | | false | Preview without changes |
| `--force` | | false | Overwrite existing on import |
| `--json` | | false | JSON output (list/diff) |
| `--help` | | | Show usage |

## Exit Codes

| Code | Meaning |
|------|---------|
| 0 | Success |
| 1 | Error (missing args, file not found, etc.) |
| 2 | Dry-run showed changes that would be made |

## Integration

### Scheduled backup via cron

```json
{
  "name": "Weekly cron fleet backup",
  "schedule": { "kind": "cron", "expr": "0 3 * * 0", "tz": "Europe/Dublin" },
  "payload": {
    "kind": "agentTurn",
    "message": "Run: node /path/to/trackhub/skills/cron-backup/scripts/cron-backup.mjs export --max-backups 8\nReport the result briefly."
  }
}
```

### Pre-change safety net

Before editing a cron job manually:

```bash
node cron-backup.mjs export --job "my job name"
# ... make changes ...
# if something breaks:
node cron-backup.mjs import --force --job "my job name"
```

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。