Old deployments piling up like junk mail? Keep the last 2, delete the archaeology. Disk space says thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| # List all deployments except the last 2
ls -ltr /opt/crafter/data/deployer/targets/ | \
grep crafter | \
awk '{print $9}' | \
sed 's/-default.yaml//g' | \
head -n -2 > /tmp/1.txt
# Delete target configurations
for each in `cat /tmp/1.txt`; do
echo "deleting $each in target"
rm -rf data/deployer/targets/$each-default.yaml
rm -rf data/repos/sites/$each
done
# Wait for filesystem sync
sleep 2m
# Delete repositories
for each in `cat /tmp/1.txt`; do
echo "deleting $each in repo"
rm -rf data/deployer/targets/$each-default.yaml
rm -rf data/repos/sites/$each
done
|
What it does:
- Lists all deployment targets sorted by modification time
- Keeps the last 2 deployments
- Removes target YAML configs and site repositories
- Waits 2 minutes between cleanup phases
Warning:
- This is destructive - verify
/tmp/1.txt contents before running - Keeps only the 2 most recent deployments
- Adjust
head -n -2 to keep different number of deployments