I
I
itgraine2018-11-02 20:01:55
Backup
itgraine, 2018-11-02 20:01:55

How to back up websites on VPS?

Hello!
Tell me how easier it is to organize backup of sites and their databases? What packages are needed for this? I have lamp set up on ubuntu 16.04 without control panel.
You need to make automatic copies of files and mysql every three days or a week, and have new copies replace the old ones.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan, 2018-11-09
@itgraine

This copying option using Cron is suitable https://vps.ua/wiki/install-linux-vps/cron/backup/ ?

T
TyzhSysAdmin, 2018-11-02
@POS_troi

Are you doing it by hand now? What prevents it from being processed into a regular bash script?
Well, okay, here's https://habr.com/post/51966/ :)

S
Sanes, 2018-11-03
@Sanes

On Ansible, the script is written in just an hour.

More or less like this
---
 - hosts: 'all'
   gather_facts: no
   vars_files:
    - 'vars/main.yml'

   tasks:
    - name: 'Sync'
      synchronize: src=/var/www/{{ username }}/ dest=/var/backups/{{ username }} owner=no group=no delete=yes
      tags: 'update'

    - name: 'DB backup'
      mysql_db: state=dump name={{ username }} target=/var/backups/{{ username }}/{{ username }}.sql login_user=root login_password={{ mysql_root_pass }}
      tags: 'update'

    - name: 'Sync restore'
      synchronize:
       src: /var/backups/{{ username }}
       dest: /var/www/
       delete: yes
       rsync_opts:
        - "--exclude=.sql"
      become: yes
      become_user: "{{ username }}"
      tags: 'restore'

    - name: 'Del MySQL database'
      mysql_db: name={{ username }} login_user=root login_password={{ mysql_root_pass }} state=absent
      tags: 'restore'

    - name: 'Add MySQL DB'
      mysql_db: name={{ username }} encoding=utf8 login_user=root login_password={{ mysql_root_pass }} state=present
      tags: 'restore'

    - name: 'DB restore'
      mysql_db: state=import name={{ username }} target=/var/backups/{{ username }}/{{ username }}.sql login_user=root login_password={{ mysql_root_pass }}
      tags: 'restore'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question