Paperless backup automatically under Docker
In today’s digital world, you increasingly need to rely on tools such as Paperless-NGX. Here is the complete Paperless Backup automatically !
In this post, I’ll show you how to implement a robust backup strategy for your Paperless-NGX system, from configuring the backup file to automating the process.
Please note: This concerns your records, documents, accounting, tax data and all other important information that you store in Paperless.
Never forget: A hard drive can break down – due to water damage, fire, burglary or even a lightning strike.
If you want to keep your data – because you depend on it – back it up regularly!
Lost data is irretrievably lost.
More articles in this series:
- Paperless: Why document management and performance scope
- Paperless: NGX Docker installation
- Paperless: Adding documents basics
- Paperless: Customize and optimize
- Paperless: Internet Sharing Compendium
- Paperless: Apps for on the go
- Paperless backup automatically under Docker
Video: Paperless backup automatically under Docker
Language: 🇩🇪
☝️ Use YouTube subtitles for all languages.
Step 1: The Heart of the Backup – The Batch File
Paperless-NGX stores your data in two critical places: a PostgreSQL database (for metadata like titles, tags, and correspondents) and the media
directory (for the actual document files). To create a complete backup, you need to secure both components.
Here is an improved backup script that handles this task. Copy the following code into a text editor and save it as Backup Paperless.bat
.
@echo off
setlocal enabledelayedexpansion
:: Current date in YYYY-MM-DD format
for /f "tokens=2 delims==" %%I in ('"wmic os get localdatetime /value | findstr ="') do set dt=%%I
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "DATE=%YYYY%-%MM%-%DD%"
:: Destination directory for backups
:: NOTE: Adjust this path to match your configuration!
set "BACKUP_DIR=D:\Paperless_Backups"
:: Path to the Paperless media directory
:: NOTE: Adjust this path to match your configuration!
set "MEDIA_DIR=C:\Your\Path\to\paperless\media"
:: Ensure the destination folders exist
if not exist "%BACKUP_DIR%\db" (
mkdir "%BACKUP_DIR%\db"
)
if not exist "%BACKUP_DIR%\media" (
mkdir "%BACKUP_DIR%\media"
)
echo Starting PostgreSQL backup...
:: NOTE: Replace the container name with your actual name (e.g., paperless-ngx_db_1)
docker exec paperless-dbpg pg_dumpall -U paperless --encoding=UTF8 > "%BACKUP_DIR%\db\paperless_db_%DATE%.sql"
echo Starting media backup...
:: Creates a compressed TAR archive of the entire media directory
tar -czf "%BACKUP_DIR%\media\paperless_media_%DATE%.tar.gz" -C "%MEDIA_DIR%" .
:: --- Keep only THREE versions ---
echo Removing old backups...
echo ...PostgreSQL backups
for /f "skip=3 delims=" %%F in ('dir /b /o-d "%BACKUP_DIR%\db\paperless_db_*.sql"') do (
echo Deleting %%F
del "%BACKUP_DIR%\db\%%F"
)
echo ...Media backups
for /f "skip=3 delims=" %%F in ('dir /b /o-d "%BACKUP_DIR%\media\paperless_media_*.tar.gz"') do (
echo Deleting %%F
del "%BACKUP_DIR%\media\%%F"
)
echo Backup complete: %DATE%.
Important adjustments you need to make:
set "BACKUP_DIR=..."
: Set the path where you want to store your backups. An external drive or network path is ideal.set "MEDIA_DIR=..."
: Provide the absolute path to yourmedia
folder, which you configured in yourdocker-compose.yml
.docker exec ...
: Replacepaperless-dbpg
with the correct name of your PostgreSQL container. You can find this by runningdocker ps
in your command prompt.
Step 2: Automate Backups with Windows Task Scheduler
Manual backups are often forgotten. The solution is automation! With Windows Task Scheduler, you can automatically run your backup script on a schedule you define.
Here’s how to set up the task:
- Open Task Scheduler: Search for “Task Scheduler” in the Start Menu and open the application.
- Create a New Task: Click on Action > Create Basic Task… in the menu.
- Name and Describe the Task: Choose a descriptive name like “Paperless-NGX Backup” and a short description.
- Choose the Schedule:
- Trigger: Select when you want the task to start. “Daily” is a good choice for regular backups.
- Time: Set a time when your computer is on but you are not actively using it (e.g., 2:00 AM).
- Action:
- Select “Start a program.”
- For “Program/script,” enter the full path to your
Backup Paperless.bat
file (e.g.,C:\Users\YourName\Scripts\Backup Paperless.bat
). - Important: In the “Start in” field, enter the directory where the batch file is located (e.g.,
C:\Users\YourName\Scripts
).
- Finish: Click “Finish” to save the task.
From now on, your backup script will run automatically at the times you set. This simple but effective method will give you a reliable data backup, minimizing the risk of losing your digital paperwork.
Link to support / donation for the channel
PayPal Link
Bank transfer, Bitcoin and Lightning
#PaperlessNGX #Docker #SelfHosted #OpenSource #Homelab #DMS #Paperless #Anleitung #PapperlessBackup #DocumentManagement #Paperless #HomeLab #Instructions #Guide #Backup