OpenTibiaBR
GithubDiscordSponsor
  • Home
    • 📖Welcome!
    • 💵Donate
  • OpenTibiaBR
    • 🖥️Projects
      • 🐦Canary
        • About
        • Getting Started
          • Compiling
            • Linux
              • [Linux] Compiling Canary Sources
            • Windows
              • Visual Studio
                • [Windows][VC2022][CMake] Compiling Canary Sources
                • [Windows][VC2022][Solution] Compiling Canary Sources
              • WSL
                • [WSL] Compiling Canary Sources
          • Installing
            • aaPanel
              • [Linux] Canary + aaPanel + MyAAC
            • Docker
              • [Docker] Canary + MariaDB + MyAAC
            • Linux
              • Nginx + MariaDB + MyAAC
            • Windows
              • Uniform Server
                • [Windows][Basic] Canary + Uniform Server + MyAAC
              • XAMPP
                • [Windows][Advanced] Canary + XAMPP + MyAAC
        • Tutorials
          • Basic
            • Auto Backup Server Database
            • Auto Restart and Linux Logs
            • Custom Bestiary / Prey with Canary Monster Editor
            • Event Schedule Canary / OTServBR-Global
            • How to make a custom server with Canary
            • How to reset players in your database
            • How to secure a Linux server
            • SSL Certificates
            • Webhook Discord
            • [Outdated] Custom Bestiary / Prey
            • [Linux] Backup + Upload - Google Drive
            • [Linux] How to install Linux headers
            • VPS Linux
            • [Windows] SSL/HTTPS Certificate with XAMPP
          • Mapping
            • [Windows] Remere's Map Editor - Opening Canary / OTServBR-Global Map
            • [Windows] Remere's Map Editor - Converting map server id to client id
          • Programming & Scripting
            • How to add a new vocation
            • Revscriptsys
            • Guide Lua Objects
            • How to get raceId for monsters
          • Websites
            • [Canary][OTServBR-Global][GesiorAAC][MyAAC] Set up Initial Character
          • Miscellaneous
            • Useful Tutorials
            • Video Tutorials
      • 🗺️Remere's Map Editor
        • About
        • Getting Started
          • Linux
            • [Linux] Compiling Remere's Map Editor Sources
          • Windows
            • WSL
              • [WSL] Compiling Remere's Map Editor Sources
            • Visual Studio
              • [Windows][VC2022][CMake] Compiling Remere's Map Editor Sources
              • [Windows][VC2022][Solution] Compiling Remere's Map Editor Sources
      • 🎮OTClient Redemption
        • About
        • Getting Started
          • Android
            • [Android] Compiling OTClient Redemption Sources
          • Linux
            • [Linux] Compiling OTClient Redemption Sources
          • Windows
            • WSL
              • [WSL] Compiling OTClient Redemption Sources
            • Visual Studio
              • [Windows][VC2022][CMake] Compiling OTClient Redemption Sources
              • [Windows][VC2022][Solution] Compiling OTClient Redemption Sources
          • Web
            • [Web] OTClient Redemption
        • Tutorials
          • Basic
            • Client Updater
      • 🎮OTClientV8
        • About
        • Getting Started
          • Android
            • [Android] Compiling OTClientV8 Sources
          • Linux
            • [Linux] Compiling OTClientV8 Sources
          • Windows
            • WSL
              • [WSL] Compiling OTClientV8 Sources
            • Visual Studio
              • [Windows][VC2022][CMake] Compiling OTClientV8 Sources
              • [Windows][VC2022][Solution] Compiling OTClientV8 Sources
        • Features
          • Health and Mana bar backgrounds
          • HTTP support
          • OTML Improvement
          • Simple cam recorder and player
          • Updater, encryption and compression
          • WebSockets
      • ⚙️Client Editor
        • About
        • Getting Started
      • ⚙️Login Server
        • About
        • Getting Started
      • 🚀Canary Launcher
        • About
        • Getting Started
          • Windows
            • [Windows][VC2022][Solution] Compiling Canary Launcher Sources
      • 🚀Slender Launcher
        • About
        • Getting Started
          • Windows
            • [Windows][Go] Compiling Slender Launcher Sources
      • 🌐CanaryAAC
        • About
        • Informations
          • Features
          • Functions
          • API
          • Routes
          • Middleware
      • 🌐MyAAC
        • About
      • 🌐SlenderAAC
        • About
    • 🔗Downloads
      • 🎮Clients
        • Client 11
        • Client 13
          • Tutorials
            • Client with HexEditorXVI32
            • Client with Notepad++
            • Client with config.ini
            • [Windows] How to change client background
        • Minimap
      • 📑Codes
        • C++
        • Events
        • Functions
        • Libs
        • Modules
        • Others
      • 🖼️Images
        • PSDs
        • Others
      • 🗺️Maps
        • Custom
        • Global
      • 📑Revscripts
        • Actions
        • CreatureEvents
        • GlobalEvents
        • MoveEvents
        • NPCs
        • Spells
        • Systems
        • TalkActions
      • ⚔️Sprites
      • ⚙️Tools
        • Editors
        • Map Generators
      • 🌐Web Packages
        • Linux
        • Windows
      • 🌐Website Applications
        • Websites
          • CanaryAAC
            • CanaryAAC Bot
          • Gesior2012
          • GesiorAAC Global
          • MyAAC
          • MyAAC Global
          • SlenderAAC
          • ZnoteAAC
        • Applications
        • Layouts
        • APIs and SDKs
Powered by GitBook
On this page
  • Create a directory:
  • Creating a database backup:
  • Create a cron job on Linux to run the .sh file on a scheduled basis:
  • Adding cron to Linux Cron will execute the backup .sh file automatically.
  • Open the cron list:
  • Cron:
  • Permission for the .sh file:
  • After saving the .sh file with the code, add the permission so it can be executed:
  • Credits: Leotk.
  1. OpenTibiaBR
  2. Projects
  3. Canary
  4. Tutorials
  5. Basic

[Linux] Backup + Upload - Google Drive

Create a directory:

  • The directory can be inside the server folder.

  • Suggested name: backup_DB

Creating a database backup:

  • Create a .sh file in the server folder

#!/bin/bash

path="/PATH TO THE FOLDER WHERE THE BACKUP WILL BE CREATED/"     # Path where the backup of your database
nameBackup="SQL FILE NAME"                                       # Environment where it is hosted
mysqlUser="MYSQL LOGIN"                                          # Your MySQL user
mysqlPass="MYSQL PASSWORD"                                       # Your MySQL password
mysqlDatabase="DATABASE NAME"                                    # The name of your database

TIMER="$(date +'%d-%m-%Y-%H-%M')"

if [[ -z "$mysqlUser" || -z "$mysqlPass" || -z "$mysqlDatabase" ]]; then
    echo "Please fill in username, password and database in settings."
else
    # Create the backup
    mysqldump -u$mysqlUser -p$mysqlPass $mysqlDatabase > $path"/"$nameBackup"-"$TIMER".sql"

    # Change to the backup directory
    cd $path

    # Remove older backups if there are more than 10 files
    backups=($(ls -t $nameBackup-*.sql))
    if (( ${#backups[@]} > 10 )); then
        for file in "${backups[@]:10}"; do
            rm "$file"
        done
    fi

    echo "Backup Complete."
fi

Create a cron job on Linux to run the .sh file on a scheduled basis:

  • The suggestion is to have two times to generate 2 .sql files, the first at 6:10 after the default servesave, and the other at 23:10 after the server is busy.

Adding cron to Linux Cron will execute the backup .sh file automatically.

Open the cron list:

crontab -e

Cron:

10 6,23 * * * /path/for/your/script.sh
  • Remember: change the machine's time to your local time, for example:

  • sudo timedatectl set-timezone America/Sao_Paulo

  • This will ensure that cron runs the .sh files at the correct time.

Permission for the .sh file:

After saving the .sh file with the code, add the permission so it can be executed:

chmod +x backup.sh

Credits: Leotk.

Last updated 3 months ago

🖥️
🐦