文章ID:4563

下一站幸福

网站数据自动备份:一个脚本+一个计划任务搞定_我的网站

追击者

A |     (ECNS) -- The 2026 Green Computing Power Conference opened Saturday in Hohhot, Inner Mongolia Autonomous Region, with 13 projects worth 136.1 billion yuan ($18.85 billion) signed across Hohhot and Ulanqab.    More than 500 participants attended the event, which showcased pilot achievements in AI application scenarios and green power infrastructure.         Organizers said the projects span the full computing power chain — from chip testing and hardware supply to data center coordination and downstream applications such as token trading and real world AI use cases.    (By Helen Mo & intern Xu Wenda)                    。    

     一键部署OpenClaw        网站备份是出事之后最后悔没做的东西。很多人服务器被黑后才发现数据库没备份,几年的内容一夜归零。其实一个shell脚本加一个定时任务就能解决。    下面这个脚本同时备份MySQL数据库和网站源码,按日期命名,保留最近7天。Linux服务器直接放到/root/backup.sh,Windows可以改成PowerShell版本,或者把Linux脚本放在宝塔面板的Shell终端里执行。

B |     

#!/bin/bash
SITE_DIR="/www/wwwroot/yoursite"
DB_NAME="yourdb"
DB_USER="root"
DB_PASS="yourpass"
BACKUP_DIR="/backup/$(date +%Y%m%d)"

mkdir -p $BACKUP_DIR

# 备份数据库
mysqldump -u$DB_USER -p$DB_PASS --single-transaction $DB_NAME | gzip > $BACKUP_DIR/db.sql.gz

# 备份网站文件
tar -czf $BACKUP_DIR/files.tar.gz -C $(dirname $SITE_DIR) $(basename $SITE_DIR)

# 删除7天前的备份
find /backup -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
    脚本写好之后加一条crontab,每天凌晨3点执行。备份文件建议再同步一份到对象存储,比如阿里云OSS或腾讯云COS,做到异地容灾。    # crontab -e    0 3 * * * /bin/bash /root/backup.sh >> /var/log/backup.log 2>&1    数据来源:MySQL Reference Manual 8.0(mysqldump),Linux crontab官方文档
        
    

申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!。

Current article:http://sddif.chongtunkuaitaogacuiliamanzu.cfd/list_j4x0p/uazj.html

Published on:21:17:01


用户评论
用户名:
E-mail:
评价等级:               
评价内容: