新闻中心

当前位置 > 新闻中心> 电脑办公 > CPU

战争之王

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

火柴人

一 |     

     一键部署OpenClaw        网站备份是出事之后最后悔没做的东西。

二 |     The opening of the movie "The Exorcist: Believer" has been moved a week earlier to avoid competition with Taylor Swift's concert movie, the producer of the horror film, Jason Blum, confirmed Thursday on social media.Blum posted the new release date of Oct. 6 on X, formerly known as Twitter, with the hashtag #TaylorWins. "The Exorcist: Believer" and Swift's concert movie based on her smash "The Eras" tour were both first scheduled to be released on Oct. 13. Fans had dubbed the pending double release "Exorswift" on social media, but the potential of "Swifties" overshadowing the demonic film —the sixth installment in "The Exorcist" franchise— proved too powerful. 

     "Taylor Swift: The Eras Tour" smashed advanced sales records on the first day of presales for the concert movie with AMC –the movie chain distributing the film– reporting $26 million in sales on Friday.  The movie "shattered records for single-day advance ticket sales revenue at AMC," the company said in a statement. The previous record of $16.9 million was held by "Spider-Man: No Way Home," which Swift beat in just three hours,  AMC said.                 Shortly after Swift announced the movie, AMC said they bolstered their server capacity in preparation for skyrocketing demand for tickets. After the first day of presales, the chain announced all AMC theaters nationwide will show the film four times a day on Thursday, Friday, Saturday and Sunday to meet demand. On Thursday, Swift tweeted, "The Eras Tour has been the most meaningful, electric experience of my life so far and I'm overjoyed to tell you that it'll be coming to the big screen soon. Starting Oct 13th you'll be able to experience the concert film in theaters in North America!" Reporting contributed by Gina Martinez                                  。很多人服务器被黑后才发现数据库没备份,几年的内容一夜归零。

三 | 其实一个shell脚本加一个定时任务就能解决。    下面这个脚本同时备份MySQL数据库和网站源码,按日期命名,保留最近7天。Linux服务器直接放到/root/backup.sh,Windows可以改成PowerShell版本,或者把Linux脚本放在宝塔面板的Shell终端里执行。    

#!/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://84d0.linxiuhuaishuangniuzhenrua.bond/list_d6k/hb77p.html

Published on:20:21:33


文章观点支持

文章价值打分
当前文章打分0 分,共有0人打分
热门评论
热门文章