通过计划任务备份网站数据

  • A+
所属分类:运维教程

之前发表过一篇网站加速的教程《将网站放到内存中运行》一些朋友给我发邮件说,照我的方法尝试了一下,还真有些效果,不过担心的是,毕竟内存是易失性存储设备(断电数据消失)如果云主机执行了重启操作,那网站不就没了吗?

为了避免数据丢失,我们来写一个计划任务,实现网站数据备份,命令如下:

  1. crontab -e

crontab -e用于编辑当前用户的计划任务,最好使用root用户来执行,可以提高任务执行的成功率。

然后在打开的窗口中填入如下的内容:

  1. 0 1 * * * rsync -aP --delete /dev/shm/birdteam.net /backup

分别解释一下:

0代表0分钟,1代表一小时,合起来就是凌晨一点整;

* * *是代表每天,第一个代表日,第二个代表月,第三个代表周;

rsync -aP中a代表保留原属性,P代表可断点续传;

--delete指原目录中如果文件被删除了,也会删除目标目录中的对应文件,这样可以避免因为卸载主题、插件造成残留文件;

/dev/shm/birdteam.net是网站目录,birdteam.net需要修改成你网站的目录;

/backup是备份目录,如果不存在可用mkdir命令创建。

如果云主机重启了,那如何恢复内存中的网站数据呢?执行如下命令,即可在每次重启后,自动将备份中网站数据恢复到内存中:

  1. echo "rsync -aP /backup/birdteam.net /dev/shm" >> /etc/rc.local
  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:26   其中:访客  26   博主  0

    • avatar grolyrto lemcs

      Only a smiling visitant here to share the love (:, btw outstanding layout.

      • avatar clenbuterol

        You are my aspiration, I have few blogs and often run out from brand :). “Follow your inclinations with due regard to the policeman round the corner.” by W. Somerset Maugham.

        • avatar cbd oil that works 2020

          Does your blog have a contact page? I’m having a tough
          time locating it but, I’d like to send you an email. I’ve got some recommendations for your blog you might
          be interested in hearing. Either way, great blog and I look forward to seeing
          it grow over time.

          • avatar https://verksamhet.se

            What’s up to all, the contents existing at this website are really awesome for people knowledge,
            well, keep up the nice work fellows.

            • avatar rsacwgxy g

              Hi would you mind letting me know which hosting company you’re working with?
              I’ve loaded your blog in 3 completely different browsers and
              I must say this blog loads a lot faster then most.

              Can you recommend a good internet hosting provider at a fair price?
              Cheers, I appreciate it!

              • avatar look what i found

                Howdy! This is my first comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading through your articles. Can you recommend any other blogs/websites/forums that cover the same topics? Thanks for your time!