Wordrepss(博客站点)自动备份缩略图
内容目录

一、配置ssh免密登录

1-1、 在Windows客户端上配置免密登录,打开cmd终端输入 ssh-keygen -t rsa 然后直接按回车,不需要输入什么,然后会自动生成文件,文件路径在 C:\users\ 用户.ssh文件下。

Wordrepss(博客站点)自动备份插图

Wordrepss(博客站点)自动备份插图1

1-2、 复制 id_rsa.pub 文件,重命名为 authorized_keys,然后上传服务器到 /root/.ssh 的文件目录下。

Wordrepss(博客站点)自动备份插图2

1-3、 登录服务器

Wordrepss(博客站点)自动备份插图3

二、备份Wordpress

2-1、 编写shell文件 vim wp_backup
 #!/bin/bash

mysql_user="root"         ## 数据库用户名
mysql_password="123.com"  ## 数据库用户名
mysql_database="wordpress"    ## 数据库名称
wp_time=$(date +%Y%m%d) 
wp_path=/root/backup/
wp_nginx=/root/backup/nginx/        ## 工作文件夹
wp_bak=/data/wwwroot/wordpress/wp-backup/  ## 下载备份的文件夹

wp_str=date -d "1 days ago" +%Y%m%d
rm_path=/data/wwwroot/wordpress/wp-backup/backup-${wp_str}.tar.gz

wp_copy(){
          mkdir -p $wp_nginx
          cd $wp_nginx
          cp -a /usr/local/nginx/ssl $wp_nginx
          cp -a /usr/local/nginx/conf/nginx.conf $wp_nginx
          cp -a /usr/local/nginx/conf/vhost/*.conf $wp_nginx
          cp -a /data/wwwroot/wordpress/wp-config.php $wp_path
}

wp_tools(){
          cd $wp_path
          mysqldump -u"$mysql_user" -p"mysql_password" "$mysql_databse" > wordpress-"$wp_time".sql &
}

wp_up(){
          cd ~ && tar zcf backup-"$wp_time".tar.gz backup && mv backup-"$wp_time".tar.gz $wp_bak
          cd ~ && rm -rf "$wp_path"
}

wp_github(){
          cd $wp_path && git clone https://github.com/mirai-mamori/Sakurairo.git
}           ## wordpress的主题

for i in $wp_path
do
          if [ ! -d $wp_path ];then
                  wp_copy && wp_tools && wp_github && wp_up
                  echo ""$wp_time"      The backup was successful." >> $wp_bak/wp_backup.log
          else
                  echo ""$wp_time"      File already exists Backup failed." >> $wp_bck/wp_backup.log
          fi

          if [ ! -f $rm_path ];then
                  echo ""$wp_time"      The previous day's file has been deleted" >> $wp_bak/wp_backup.log
                  rm -rf $rm_path
          fi
done
2-2、 需要给wp_backup权限
chmod +x wp_backup
2-3、 测试
./wp_backup  && ls /data/wwwroot/wordpress/wp-backup
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Cloning into 'Sakurairo'...
mysqldump: Got error: 1045: Access denied for user 'root'@'127.0.0.1' (using password: YES) when trying to connect
remote: Enumerating objects: 14800, done.
remote: Counting objects: 100% (1260/1260), done.
remote: Compressing objects: 100% (524/524), done.
remote: Total 14800 (delta 751), reused 1136 (delta 698), pack-reused 13540
Receiving objects: 100% (14800/14800), 112.62 MiB | 2.37 MiB/s, done.
Resolving deltas: 100% (9545/9545), done.
backup-20230830.tar.gz  wp_backup.log

cat /data/wwwroot/wordpress/wp-backup/wp_backup.log
20230830        The backup was successful.   ## 成功备份
20230830        The previous day's file has been deleted  ## 删除前一天的备份

三、创建wp_backup.bat文件

Windows PowerShell
版权所有(C) Microsoft Corporation。保留所有权利。

安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows

PS C:\Users\25445> d:
PS D:\> md backup

    目录: D:\

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         2023/8/30     18:24                backup

PS D:\> cd backup
PS D:\backup> type .\wp-backup.bat
D:   && cd d:\backup
scp root@smallrains.net:/data/wwwroot/wordpress/wp-backup/* .

或者通过 start命令打开文件

四、创建计划任务

首先按下组合键 win+R 打开运行,然后输入 taskschd.msc 并回车。

Wordrepss(博客站点)自动备份插图4

Wordrepss(博客站点)自动备份插图5

Wordrepss(博客站点)自动备份插图6

五、运行WP-bakcup,运行后会自动下载文件

Wordrepss(博客站点)自动备份插图7

Wordrepss(博客站点)自动备份插图8

这样就可以自动备份你的Wordrepss了

本文章转载自:小张不嚣张的博客

原文链接:https://smallrains.net/2023/08/30/202308302014/

发表回复