search
HomeOperation and MaintenanceLinux Operation and MaintenanceLinux MySQL scheduled backup and upload to git repository

Introduction

When we deploy our small and medium-sized projects, we usually choose mysql as our storage tool for data storage. So for a large project, every day The amount of data is very large. For the data generated every day, if our website or server is attacked one day, our data loss will be an explosion, so it is natural to design a backup of the database. So what kind of backup is What do we want?

We may store the backed up data files in the server directory. The backup cycle is of course based on the amount of data. Here we usually back up once every morning. After backup The files are stored in the directory of our server, but if the server crashes one day, the backed up files will be gone. So we imagine a good solution is to back up the database every day and automatically submit each backup to the remote warehouse. Here I take Code Cloud as an example.

Recommended study: "linux tutorial"

Code Cloud

First establish a remote warehouse. Here I chose Code Cloud

to create a new private warehouse. Of course, in order to submit files without a password every time, the ssh key can be generated in the server

Create a new backup on the server

In order to store the backed up files on the server, create a new backup directory

$ mkdir /bak

After entering the directory, continue to create two folders, mysqlBak and shDir, one for the script file, One is to put the specific backup files.

Now we can create a new script, enter the shDir directory and execute

$ vim mysqlBak.sh

The specific code is as follows:

#!bin/sh
################### 数据库配置信息 #######################
createAt=`date +%Y-%m-%d-%H:%M:%S`
user=root
passwd=ghc1996
dbname=ispace
mysql_back_path=/bak/mysqlBak
################### 执行命令 #######################
mysqldump -u $user -p$passwd $dbname > $mysql_back_path/$createAt.sql
cd /bak/mysqlBak
/usr/local/git/bin/git add .
/usr/local/git/bin/git commit -m $createAt
/usr/local/git/bin/git push

This is just a It is a simple script, I think it is easy to understand for those who know Linux. What it does is back up the database and push it to the remote warehouse.

So since it is a script, we need to indicate when to execute this script and specify the execution of the script.

$ crontab -e

We hope to perform a backup in the early morning of every day and add it to the remote warehouse, then add

$ 0 0 * * * /bin/sh /bak/shDir/mysqlbak.sh

There are only five parts of the time specified in the Linux crontab

Linux MySQL scheduled backup and upload to git repository

Use the command crontab -e and edit the timing script directly. The specific name of the time

For example:

0 0,3,7,9,12,15,18,21,23 * * * /bin/sh /bak/shell/mysqlBak.sh

In this case, I will be at 0,,3,7,9,12,15,18,21,23 o'clock every day Execute this script file, then this will realize the basic database backup

Execute the scheduled task:

$ crontab -l

If the service does not start, then restart the scheduled task

$ systemctl restart crond

Then Now that the scheduled task has been started, the prerequisite for submitting the remote warehouse is to generate the ssh key on the server and add it to the code cloud, which is also mentioned above.

For the directory where files need to be submitted, initialize the git directory. Okay, this round can constitute the tasks we need.

Of course you may encounter some problems during the process, I have listed them in the relevant links below.

This way As a result, we can back up our database in the early morning of every day and submit it to the remote warehouse of our code cloud at the same time. This is also the effect we want.

I also said that the backup cycle depends on us It depends on the size of the data volume of the project.

Each framework has its own backup mechanism. What I write here is a general backup mechanism implemented by ourselves

The above is the detailed content of Linux MySQL scheduled backup and upload to git repository. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:ruoxiaozh. If there is any infringement, please contact admin@php.cn delete
Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Understanding Linux's Maintenance Mode: The EssentialsUnderstanding Linux's Maintenance Mode: The EssentialsApr 14, 2025 am 12:04 AM

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

How Debian improves Hadoop data processing speedHow Debian improves Hadoop data processing speedApr 13, 2025 am 11:54 AM

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

How to learn Debian syslogHow to learn Debian syslogApr 13, 2025 am 11:51 AM

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

How to choose Hadoop version in DebianHow to choose Hadoop version in DebianApr 13, 2025 am 11:48 AM

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment