Periodic Database Backup to Gitlab Private Repository Using Flysystem and Cronjob

This page summarizes the projects mentioned and recommended in the original post on

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • flysystem-gitlab-storage

    Gitlab Storage filesystem for Flysystem (

  • Flysystem Gitlab Adapter by Roy Voetman

  • mysqldump-php

    PHP version of mysqldump cli that comes with MySQL

  • Mysqldump PHP by ifsnop

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • profile

  • Visit Gitlab Access Token page and create your access token:

  • ntfy

    Send push notifications to your phone or desktop using PUT/POST

  • $db_host = 'YOUR_DB_HOST'; $db_user = 'YOUR_DB_USER'; $db_pass = 'YOUR_DB_PASS'; $db_name = 'YOUR_DB_NAME'; // Create database name $database_name = 'backup-on-YOUR-DB-NAME-'.date('d-m-Y').'.sql'; // Define path for dump on disk $app_path = 'YOUT_PATH'; if ( file_exists($app_path . $database_name) ) { $database_name = date('His').'-'.$database_name; // Dump database $dump = new IMysqldump\Mysqldump('mysql:host='. $db_host .';dbname='. $db_name .'', $db_user, $db_pass); $dump->start( $app_path . $database_name ); } else { // Dump database $dump = new IMysqldump\Mysqldump('mysql:host='. $db_host .';dbname='. $db_name .'', $db_user, $db_pass); $dump->start( $app_path . $database_name ); } $file_content = file_get_contents( $app_path . $database_name ); $dir_backup = 'db-'.strtolower(date('F-Y')); // Result like: db-december-2021 // Gitlab Flysystem Config $personal_access_token = "GITLAB_ACCESS_TOKEN"; $project_id = "PROJECT_ID"; $branch = "BRANCH_NAME"; $cloud_url = ""; // <-- default or use your gitlab instance url // Create a GitLab Client to talk with the API $client = new Client( $personal_access_token , $project_id, $branch, $cloud_url); // Create the Adapter that implements Flysystems AdapterInterface $adapter = new GitlabAdapter($client); // Use FileSystem $filesystem = new Filesystem($adapter); // Check if directory backup is exists on repository if ( $filesystem->has($dir_backup) ) { // If exists then write database inside $filesystem->write($dir_backup.'/'.$database_name, $file_content); } else { // If not exists then create directory $filesystem->createDir($dir_backup); // then write database inside $filesystem->write($dir_backup.'/'.$database_name, $file_content); } file_get_contents('', false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: text/plain\r\n" . "Title: Daily Database Backup!\r\n" . "Priority: default\r\n" . "Tags: bell,tada,partying_face", 'content' => 'Backup successful 😀' ] ]));

  • Flysystem

    Abstraction for local and remote filesystems

  • Ok, I need the Flysystem Library to do CRUD transactions with the Gitlab API.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts