-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcron-tab.sh
More file actions
executable file
·35 lines (27 loc) · 1015 Bytes
/
Copy pathcron-tab.sh
File metadata and controls
executable file
·35 lines (27 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
echo "Setting up cron job for postgres-backup..."
mkdir -p /home/$(whoami)/backup
mkdir -p /home/$(whoami)/backup/logs
CRON_JOB="0 0 * * * cd /home/$(whoami)/backup && ./postgres-backup >> logs/backup.log 2>&1"
if crontab -l 2>/dev/null | grep -q "postgres-backup"; then
echo "Cron job for postgres-backup already exists!"
echo "Current crontab:"
crontab -l | grep postgres-backup
else
# Add the cron job
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -
echo "✅ Cron job added successfully!"
echo "The backup will run every night at midnight (00:00)"
fi
echo ""
echo "📋 Current crontab entries:"
crontab -l
echo ""
echo "📁 Make sure these files are in /home/$(whoami)/backup/:"
echo " - postgres-backup (binary)"
echo " - .env (environment variables)"
echo ""
echo "📝 Log files will be created in: /home/$(whoami)/backup/logs/backup.log"
echo ""
echo "🧪 To test the backup manually, run:"
echo " cd /home/$(whoami)/backup && ./postgres-backup"