Monday, 13 March 2023

How to backup journald daily?

 #!/bin/bash


# Set the backup directory

BACKUP_DIR=/logs


# Create the backup directory if it doesn't exist

mkdir -p $BACKUP_DIR


# Get the current date in the format "YYYY-MM-DD"

DATE=$(date +%Y-%m-%d)

PREV_DATE=$(date -u -d "1 day ago 00:00:01" +"%Y-%m-%d %H:%M:%S")


# Loop through all running containers and backup their logs

for container in $(docker ps --format '{{.Names}}'); do

  journalctl -b CONTAINER_NAME=$container --since "$PREV_DATE" >> $BACKUP_DIR/$container-$DATE.log

done


---

You also need to set the /etc/docker/daemon and restart the docker

{
    "default-runtime": "nvidia",
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "log-driver": "journald"
}

No comments:

Post a Comment