Jaimodiji commited on
Commit
f6eb420
·
verified ·
1 Parent(s): c56bc72

Fix: Exclude temporary SQLite files from backup

Browse files
Files changed (1) hide show
  1. hf_backup.mjs +8 -8
hf_backup.mjs CHANGED
@@ -3,24 +3,25 @@ import fs from 'fs';
3
  import path from 'path';
4
 
5
  const REPO_ID = 'Jaimodiji/colorrm-test-storage';
6
- // Hardcoded token (Base64 to bypass HF upload security scanner)
7
- const TOKEN = Buffer.from('aGZfWWtNa2l2RWpuTVJsV2hhUnBHcG9uZmZKcXZLUnJSTVhXUw==', 'base64').toString();
8
  const BACKUP_INTERVAL = 60 * 1000; // 1 minute
9
  const LOCAL_STATE_DIR = '.wrangler/state/v3';
10
 
11
  async function backup() {
12
  console.log(`[${new Date().toISOString()}] Starting backup to HF Dataset...`);
13
 
 
 
 
 
 
14
  if (!fs.existsSync(LOCAL_STATE_DIR)) {
15
  console.log(`[${new Date().toISOString()}] Local state directory not found yet. Skipping...`);
16
  return;
17
  }
18
 
19
  try {
20
- // We use hf upload to sync the local state directory to the dataset
21
- // Using --repo-type dataset ensures it goes to the right place
22
- // Adding --no-create-repo to avoid 401 errors if the token doesn't have repo creation permissions
23
- const command = `hf upload ${REPO_ID} ${LOCAL_STATE_DIR} .wrangler_backup --repo-type dataset --token ${TOKEN} --commit-message "Automated backup ${new Date().toISOString()}" --no-create-repo --quiet`;
24
 
25
  execSync(command, { stdio: 'inherit' });
26
  console.log(`[${new Date().toISOString()}] Backup successful.`);
@@ -29,7 +30,6 @@ async function backup() {
29
  }
30
  }
31
 
32
- // Ensure HF CLI is installed and in path (handled by Dockerfile, but for safety)
33
  console.log('HF Backup Worker started.');
34
  setInterval(backup, BACKUP_INTERVAL);
35
- backup(); // Run once immediately
 
3
  import path from 'path';
4
 
5
  const REPO_ID = 'Jaimodiji/colorrm-test-storage';
6
+ const TOKEN = process.env.HF_TOKEN;
 
7
  const BACKUP_INTERVAL = 60 * 1000; // 1 minute
8
  const LOCAL_STATE_DIR = '.wrangler/state/v3';
9
 
10
  async function backup() {
11
  console.log(`[${new Date().toISOString()}] Starting backup to HF Dataset...`);
12
 
13
+ if (!TOKEN) {
14
+ console.error('HF_TOKEN environment variable is not set. Skipping backup.');
15
+ return;
16
+ }
17
+
18
  if (!fs.existsSync(LOCAL_STATE_DIR)) {
19
  console.log(`[${new Date().toISOString()}] Local state directory not found yet. Skipping...`);
20
  return;
21
  }
22
 
23
  try {
24
+ const command = `hf upload ${REPO_ID} ${LOCAL_STATE_DIR} .wrangler_backup --repo-type dataset --token ${TOKEN} --commit-message "Automated backup ${new Date().toISOString()}" --exclude "*.sqlite-shm" --exclude "*.sqlite-wal" --quiet`;
 
 
 
25
 
26
  execSync(command, { stdio: 'inherit' });
27
  console.log(`[${new Date().toISOString()}] Backup successful.`);
 
30
  }
31
  }
32
 
 
33
  console.log('HF Backup Worker started.');
34
  setInterval(backup, BACKUP_INTERVAL);
35
+ backup();