分类 运维 下的文章

在使用mysql的过程中,如果开启二进制日志就会产生binlog文件。它可以帮助我们进行增量备份和恢复的操作。但是,如果不合理配置,binlog就会越来越大,导致磁盘空间不足。

清理的方法有四种,分别对应不同的情况:

1、手动清理binlog数据,使用下列几条SQL语句之一

PURGE MASTER LOGS TO 'binlog.000020';  #清理binlog.000020之前的binlog数据和文件
PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 60 DAY);   #清理距今60天之前的binlog数据和文件
PURGE MASTER LOGS BRFORE '2022-01-01 12:00:00';#清理2022-01-01 12:00前的binlog数据和文件

2、添加在配置文件中

expire_logs_days = 0   #文件中如果不写此项,那就默认不清理
expire_logs_days = 5   #自动清除5天以上的binlog数据和文件

3、删除全部binlog(一般不推荐)

reset master;

4、物理删除(各种不推荐)

rm -f binlog.000001

打开“服务器管理器”,在左侧列表中选中“本地服务器”

将右侧“远程桌面”功能的选项修改为“启用”,注意取消下面复选框的选中状态

“Win键”+R 组合键调出运行窗口,输入“gpedit.msc”调出组策略编辑器

计算机配置->管理模板->Windows 组件->远程桌面服务->远程桌面会话主机->连接 的路径,找到“将远程桌面服务的用户限制到单独的远程桌面会话”配置项

打开配置界面,选择“已禁用”选项

前提:需开启mysql日志

/www/server/mysql/bin/mysqlbinlog  /www/server/data/mysql-bin.000048 |grep 'table_name' >>binlog20200611.sql

/www/server/mysql mysql的安装目录

/www/server/data/mysql-bin.000048 mysql日志文件

table_name 指定表的名称

binlog20200611.sql 执行操作后保存sql文件的路径及名称 未指定路径的话则保存在当前操作的目录

备份navicat数据库连接信息,导入后需要输入密码才可以连接数据库

<?php
class NavicatPassword
{
    protected $version = 0;
    protected $aesKey = 'libcckeylibcckey';
    protected $aesIv = 'libcciv libcciv ';
    protected $blowString = '3DC5CA39';
    protected $blowKey = null;
    protected $blowIv = null;
     
    public function __construct($version = 12)
    {
        $this->version = $version;
        $this->blowKey = sha1('3DC5CA39', true);
        $this->blowIv = hex2bin('d9c7c3c8870d64bd');
    }
     
    public function encrypt($string)
    {
        $result = FALSE;
        switch ($this->version) {
            case 11:
                $result = $this->encryptEleven($string);
                break;
            case 12:
                $result = $this->encryptTwelve($string);
                break;
            default:
                break;
        }
         
        return $result;
    }
     
    protected function encryptEleven($string)
    {
        $round = intval(floor(strlen($string) / 8));
        $leftLength = strlen($string) % 8;
        $result = '';
        $currentVector = $this->blowIv;
         
        for ($i = 0; $i < $round; $i++) {
            $temp = $this->encryptBlock($this->xorBytes(substr($string, 8 * $i, 8), $currentVector));
            $currentVector = $this->xorBytes($currentVector, $temp);
            $result .= $temp;
        }
         
        if ($leftLength) {
            $currentVector = $this->encryptBlock($currentVector);
            $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
        }
         
        return strtoupper(bin2hex($result));
    }
     
    protected function encryptBlock($block)
    {
        return openssl_encrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    }
     
    protected function decryptBlock($block)
    {
        return openssl_decrypt($block, 'BF-ECB', $this->blowKey, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING);
    }
     
    protected function xorBytes($str1, $str2)
    {
        $result = '';
        for ($i = 0; $i < strlen($str1); $i++) {
            $result .= chr(ord($str1[$i]) ^ ord($str2[$i]));
        }
         
        return $result;
    }
     
    protected function encryptTwelve($string)
    {
        $result = openssl_encrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
        return strtoupper(bin2hex($result));
    }
     
    public function decrypt($string)
    {
        $result = FALSE;
        switch ($this->version) {
            case 11:
                $result = $this->decryptEleven($string);
                break;
            case 12:
                $result = $this->decryptTwelve($string);
                break;
            default:
                break;
        }
         
        return $result;
    }
     
    protected function decryptEleven($upperString)
    {
        $string = hex2bin(strtolower($upperString));
         
        $round = intval(floor(strlen($string) / 8));
        $leftLength = strlen($string) % 8;
        $result = '';
        $currentVector = $this->blowIv;
         
        for ($i = 0; $i < $round; $i++) {
            $encryptedBlock = substr($string, 8 * $i, 8);
            $temp = $this->xorBytes($this->decryptBlock($encryptedBlock), $currentVector);
            $currentVector = $this->xorBytes($currentVector, $encryptedBlock);
            $result .= $temp;
        }
         
        if ($leftLength) {
            $currentVector = $this->encryptBlock($currentVector);
            $result .= $this->xorBytes(substr($string, 8 * $i, $leftLength), $currentVector);
        }
         
        return $result;
    }
     
    protected function decryptTwelve($upperString)
    {
        $string = hex2bin(strtolower($upperString));
        return openssl_decrypt($string, 'AES-128-CBC', $this->aesKey, OPENSSL_RAW_DATA, $this->aesIv);
    }
};
//需要指定版本两种,11或12
//$navicatPassword = new NavicatPassword(12);
$navicatPassword = new NavicatPassword(11);
//解密
$decode = $navicatPassword->decrypt('53DC5F1A62D25A5E78E7');
echo $decode."\n";
?>

公司使用的软件供应商的软件只开发了备份功能,没有覆盖和定时删除,磁盘经常会占满,需要手动删除,便有了这个需求。

@echo off 
forfiles /p D:\test /m A*.zip /d -6 /c "cmd /c del @path"

A*.zip 开头为A的.zip文件

-6 6天前文件