https://github.com/zonca/git-cron-backup-ansible
https://github.com/zonca/git-cron-backup-ansible
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/zonca/git-cron-backup-ansible
- Owner: zonca
- License: mit
- Created: 2017-10-27T10:42:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-27T16:19:20.000Z (over 8 years ago)
- Last Synced: 2025-11-28T11:37:35.183Z (7 months ago)
- Language: Shell
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
git based cron backup
=============
Git is very convenient for backing up folders of text files, for example `/var/log`,
on many servers is just a few tens of MB.
Git offers a easy way to setup a offsite incremental backup for free, accessible
via browser and with good search functionality.
This Ansible playbook sets up a remote Ubuntu/Debian server with a hourly cron job
to run the backup operation and push to a remote repository.
## Configure the remote server
* Make sure it runs Ubuntu or Debian
* Make sure it has Python 3 (or 2) preinstalled
* Copy your SSH keys so that you can ssh with no need to type a password
* Configure `sudo` to run without a password so `ansible` can become `root`
## Configure your local machine
Install `ansible`, at least 2.4.0, but it might work with older versions
## Configure the repository
Create a private repository for example on Github or Bitbucket. For example
Create a new ssh keypair with `ssh-keygen` on your local machine and add the public key as a **deploy key** in the settings,
make sure to grant write privileges.
## Configure the playbook
* Clone the repository on your local machine
* Rename the `hosts.example` file to `hosts`
* Configure the paramters of the server you would like to configure:
* `SERVERURL`
* `private_deploy_key=./id_rsa`, path to the **private** key you created above, it will be copied in `/root/.ssh` on the remote server
* `git_repository=git@github.com:GITHUBUSERNAME/logbackup`, use the SSH path
* `ansible_user=SSHUSERNAME`, if you remove this, it will use `ubuntu` as username
* `folder_to_backup=/var/log`
## Run the playbook
On your local machine, from the repository root folder, run:
ansible-playbook site.yml
This will install the deploy key on root, initialize the repo in the remote folder and prepare the remote.
It will install a script in `/etc/cron.hourly` so that the backup will run regularly.
Finally it will launch the first backup via `run-parts` so that we can check that it is picking up
the script correctly.