Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double execution of backup on 1st of each month leads to DB backup failure #5089

Closed
MisterCodeRalf opened this issue May 10, 2024 · 1 comment

Comments

@MisterCodeRalf
Copy link

Detailed description of the problem

on every 1st of each month the following suggested entry in crontab:
00 04 * * * /path/to/elabctl backup

leads to a double execution of the backup. This is an issue of crontab, nevertheless this results in two failures in the gzip compression of the sql dump file and the whole DB backup is useless on that date.

Expected Behavior

clean gzipped sql dump for each day

Steps to reproduce the behavior

  1. crontab -e
  2. 00 04 * * * /path/to/elabctl backup
  3. check gziped backup files over two months
  4. on the first of each month the compressed sql dump files are corrupt

Do you have any idea what may have caused this?

crontab fires two instances simultaneously of the backup script on the 1st of each month

Do you have an idea how to solve the issue?

Solution: this might be prevented simply by using the flock command in the crontab entry such as:

00 04 * * * flock -n /path/to/some/lockfile /path/to/elabctl backup >> log.txt 2>> err.log.txt

or: some locking logic will be implemented in the elabctl script.

What is your docker-compose configuration?

version: '3'
services:
  web:
    image: elabftw/elabimg:5.0.4
    restart: always
    container_name: elabftw
    cap_drop:
        - SYS_ADMIN
        - AUDIT_WRITE
        - MKNOD
        - SYS_CHROOT
        - SETFCAP
        - NET_RAW
        - SYS_PTRACE
    environment:
        - DB_HOST=mysql
        - DB_PORT=3306
        - DB_NAME=elabftw
        - DB_USER=elabftw
        - PHP_TIMEZONE=Europe/Paris
        - TZ=Europe/Paris
        - SITE_URL=http://enlab.uni-jena.de
        - SERVER_NAME=enlab.uni-jena.de
        - DISABLE_HTTPS=true
        - ENABLE_LETSENCRYPT=true
    ports:
        - '8080:443'
    volumes:
        - /var/elabftw/web:/elabftw/uploads
        - /etc/letsencrypt:/ssl
    networks:
      - elabftw-net
  mysql:
    image: mysql:8.0
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    container_name: mysql
    cap_drop:
        - AUDIT_WRITE
        - MKNOD
        - SYS_CHROOT
        - SETFCAP
        - NET_RAW
    cap_add:
        - SYS_NICE
    environment:
        - MYSQL_DATABASE=elabftw
        - MYSQL_USER=elabftw
        - TZ=Europe/Paris
    volumes:
        - /var/elabftw/mysql:/var/lib/mysql
    expose:
      - '3306'
    networks:
      - elabftw-net
networks:
  elabftw-net:

Output of uname -a

Linux enlab-app.vmguest.uni-jena.de 5.4.0-181-generic #201-Ubuntu SMP Thu Mar 28 15:39:01 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of cat /etc/os-release

Linux enlab-app.vmguest.uni-jena.de 5.4.0-181-generic #201-Ubuntu SMP Thu Mar 28 15:39:01 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
install@enlab-app:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Output of docker info

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  compose: Docker Compose (Docker Inc., v2.24.5)
  scan: Docker Scan (Docker Inc., v0.23.0)

Server:
 Containers: 4
  Running: 2
  Paused: 0
  Stopped: 2
 Images: 19
 Server Version: 25.0.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
 Kernel Version: 5.4.0-181-generic
 Operating System: Ubuntu 20.04.6 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.925GiB
 Name: enlab-app.vmguest.uni-jena.de
 ID: b508cb1c-f0f7-4545-9ef9-0ce61cb9d8c0
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http://internet4nzm.rz.uni-jena.de:3128
 HTTPS Proxy: http://internet4nzm.rz.uni-jena.de:3128
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support

Relevant php error log entry

NA

Additional information

NA

@NicolasCARPi
Copy link
Contributor

I'm not sure I understand how this happens.

00 04 * * * /path/to/elabctl backup means: everyday at 4AM.

Why would a second one start the first of the month? Do you have something in cron.monthly or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants