Back to n8n Management Hub

n8n Docker – Disk Cleanup & Auto‑Maintenance

Quick guide to reclaim space and automate disk maintenance for n8n running in Docker on DigitalOcean Droplets.
คู่มือด่วนสำหรับเพิ่มพื้นที่และตั้งค่าบำรุงรักษาดิสก์อัตโนมัติบน Droplet ที่รัน n8n Docker

🔧 Command Generator 🔧 เครื่องมือสร้างคำสั่ง

Generate custom commands with your specific paths and settings.
สร้างคำสั่งที่กำหนดเองด้วย path และการตั้งค่าของคุณ

Navigate to n8n Directory ไปยังโฟลเดอร์ n8n

Your navigation and restart commands will appear here.

Generate Webhook Report Script สร้างสคริปต์รายงาน Webhook

Your webhook script will appear here.

1. Check Current Disk Usage 1. ตรวจสอบพื้นที่ดิสก์ปัจจุบัน

df -h

2. Expand Disk / Partition (Optional) 2. ขยายดิสก์ / พาร์ทิชัน (ถ้าจำเป็น)

  1. Check new size / ตรวจสอบขนาดใหม่
    lsblk
  2. Install growpart / ติดตั้ง growpart
    sudo apt update && sudo apt install cloud-guest-utils
  3. Grow partition / ขยายพาร์ทิชัน
    sudo growpart /dev/vda 1
  4. Resize filesystem / ปรับขนาดไฟล์ระบบ
    sudo resize2fs /dev/vda1
    Note: Use xfs_growfs / for XFS filesystem.
    หมายเหตุ: ใช้ xfs_growfs / สำหรับไฟล์ระบบ XFS

3. Manual Docker Cleanup 3. ล้าง Docker ด้วยตนเอง

docker system prune -af --volumes
Warning: This will remove all unused containers, networks, images, and volumes.
คำเตือน: คำสั่งนี้จะลบ containers, networks, images และ volumes ที่ไม่ได้ใช้ทั้งหมด

4. Configure Daily Cron Jobs 4. ตั้งค่า Cron Jobs รายวัน

  1. Open crontab editor / เปิดตัวแก้ไข crontab
    sudo crontab -e
    First time? You'll be asked to choose an editor. Select nano (usually option 1) for beginners.
    ครั้งแรก? จะถูกถามให้เลือกตัวแก้ไข เลือก nano (มักจะเป็นตัวเลือก 1) สำหรับผู้เริ่มต้น
  2. Add these jobs / เพิ่มงานเหล่านี้
    0 3 * * * docker system prune -af --volumes >> /var/log/docker_prune.log 2>&1
    0 4 * * * find /var/lib/docker/volumes/n8n_data/_data/binaryData -type f -mtime +7 -delete >> /var/log/binary_data_cleanup.log 2>&1
    0 5 * * * sqlite3 /var/lib/docker/volumes/n8n_data/_data/database.sqlite "VACUUM;" >> /var/log/db_vacuum.log 2>&1
    0 6 * * * echo "$(date +'%F %T') $(df -h / | tail -1 | awk '{print $5}')" >> /var/log/disk_trend.log
    How to paste: Use Ctrl+Shift+V or right-click and paste. Go to the bottom of the file and add these lines.
    วิธีวาง: ใช้ Ctrl+Shift+V หรือคลิกขวาแล้ววาง ไปที่ท้ายไฟล์และเพิ่มบรรทัดเหล่านี้
  3. Save and exit / บันทึกและออก
    Press Ctrl+X, then Y, then Enter

5. Manual Database VACUUM 5. VACUUM ฐานข้อมูลด้วยตนเอง

  1. Install sqlite3 / ติดตั้ง sqlite3
    sudo apt install sqlite3
  2. Run VACUUM / รัน VACUUM
    sqlite3 /var/lib/docker/volumes/n8n_data/_data/database.sqlite "VACUUM;"

6. n8n Execution Data Pruning 6. ลบข้อมูล Execution ของ n8n อัตโนมัติ

  1. Find your docker-compose.yml file / หาไฟล์ docker-compose.yml ของคุณ
    find /home -name "docker-compose.yml" 2>/dev/null
    This shows the location of your docker-compose.yml file. Remember this path!
    คำสั่งนี้แสดงตำแหน่ง ของไฟล์ docker-compose.yml จำ path นี้ไว้!
  2. Navigate to the directory / ไปยังโฟลเดอร์
    cd /path/to/your/n8n/folder
    Replace the path! Use the actual path from step 1. For example: cd /home/user/n8n
    เปลี่ยน path! ใช้ path จริงจากขั้นตอน 1 เช่น: cd /home/user/n8n
  3. Make a backup copy / สำรองไฟล์
    cp docker-compose.yml docker-compose.yml.backup
    Safety first! This creates a backup in case something goes wrong.
    ความปลอดภัยก่อน! สร้างไฟล์สำรองกรณีมีปัญหา
  4. Edit the docker-compose.yml file / แก้ไขไฟล์ docker-compose.yml
    nano docker-compose.yml
  5. Find the environment section / หาส่วน environment
    Look for a section like this:
    environment:
      - N8N_HOST=...
      - N8N_PORT=...
    หาส่วนที่มีลักษณะแบบนี้:
    environment:
      - N8N_HOST=...
      - N8N_PORT=...
  6. Add these two lines / เพิ่มสองบรรทัดนี้
          - N8N_PRUNE_DATA=true
          - N8N_PRUNE_DATA_MAX_AGE=14
    Add at the end of the environment section. Make sure the spacing matches other lines (6 spaces before the dash).
    เพิ่มที่ท้าย ของส่วน environment ให้แน่ใจว่าการเว้นวรรคตรงกับบรรทัดอื่น (6 ช่องว่างก่อนเครื่องหมายขีด)
  7. Save and exit / บันทึกและออก
    Press Ctrl+X, then Y, then Enter
  8. Restart n8n containers / รีสตาร์ท n8n containers
    docker compose down && docker compose up -d
    This stops and starts n8n with the new settings. It may take 1-2 minutes.
    คำสั่งนี้หยุดและเริ่ม n8n ด้วยการตั้งค่าใหม่ อาจใช้เวลา 1-2 นาที
  9. Verify it's working / ตรวจสอบว่าทำงาน
    docker compose ps
    Check the status - you should see "Up" status for n8n containers.
    ตรวจสอบสถานะ - ควรเห็นสถานะ "Up" สำหรับ n8n containers

7. Send Daily Log Report to n8n Webhook 7. ส่งรายงานล็อกรายวันไปยัง n8n Webhook

  1. Install jq / ติดตั้ง jq
    sudo apt install -y jq
  2. Create script / สร้างสคริปต์
    sudo nano /root/send_logs_to_n8n.sh
  3. Paste this code / วางโค้ดนี้
    #!/bin/bash
    # Replace YOUR_N8N_WEBHOOK_URL with your actual webhook URL
    WEBHOOK_URL="https://your-n8n-instance.com/webhook/maintenance-logs"
    
    DOCKER_LOG=$(tail -1 /var/log/docker_prune.log 2>/dev/null)
    BINARY_LOG=$(tail -1 /var/log/binary_data_cleanup.log 2>/dev/null)
    VACUUM_LOG=$(tail -1 /var/log/db_vacuum.log 2>/dev/null)
    DISK_LOG=$(tail -1 /var/log/disk_trend.log 2>/dev/null)
    
    curl -X POST -H "Content-Type: application/json" -d "$(jq -n \
      --arg docker "$DOCKER_LOG" \
      --arg binary "$BINARY_LOG" \
      --arg vacuum "$VACUUM_LOG" \
      --arg disk "$DISK_LOG" \
      '{docker_prune:$docker, binary_data_cleanup:$binary, db_vacuum:$vacuum, disk_trend:$disk}')" \
      "$WEBHOOK_URL"
    Important: Replace https://your-n8n-instance.com/webhook/maintenance-logs with your actual n8n webhook URL!
    สำคัญ: เปลี่ยน https://your-n8n-instance.com/webhook/maintenance-logs เป็น URL webhook จริงของคุณ!
  4. Save and exit / บันทึกและออก
    Press Ctrl+X, then Y, then Enter
  5. Make script executable / ทำให้สคริปต์รันได้
    chmod +x /root/send_logs_to_n8n.sh
    This step is required! Without this, the script won't run automatically.
    ขั้นตอนนี้จำเป็น! ถ้าไม่ทำ สคริปต์จะไม่รันอัตโนมัติ
  6. Add cron job / เพิ่ม cron job
    sudo crontab -e
  7. Add this line at the bottom / เพิ่มบรรทัดนี้ที่ท้ายไฟล์
    15 6 * * * /root/send_logs_to_n8n.sh
    This runs at 06:15 daily - 15 minutes after the disk logging, so all logs are ready.
    จะรันเวลา 06:15 ทุกวัน - 15 นาทีหลังจากบันทึกดิสก์ เพื่อให้ log ทั้งหมดพร้อม
  8. Save and exit / บันทึกและออก
    Press Ctrl+X, then Y, then Enter

Final Result ผลลัพธ์สุดท้าย