Skip to content

Instantly share code, notes, and snippets.

@wesort wesort/autobackup.sh
Last active Aug 16, 2019

Embed
What would you like to do?
Automatic daily backup from production site to GitHub
# Shell script to automatically backup current branch to GitHub
# Tested on Digital Ocean and Webfaction
git add .
git commit -m "Automatic daily backup via cronjob"
git push
# Instructions
# 1. SSH into the server
# 2.1 Create this file at root of the repo to backup: $ touch autobackup.sh
# 2.2 Add the commands shown in this file: $ vim autobackup.sh
# 3. Set permission to execute: $ chmod 777 autobackup.sh
# 4. Ensure the current (master) branch is set to track upstream: $ git push -u origin master
# 5.1 Test that the command runs manually: $ sh autobackup.sh
# 5.2 Check Github.com for the commit of the autobackup.sh file
# 6.1 Setup cronjob to run the file:
# $ crontab -e
# 6.2 Create or edit a new line replacing "example.com" accordingly
# 6.3 Example of nightly at 3am:
# 0 3 * * * cd ~/example.com/ && ./autobackup.sh > /dev/null
# NB: To receive emails from cron, set your email address at the top of the crontab
# MAILTO=name@example.com
# NB: " > /dev/null" Only errors are emailed.
# 6.4 Crontab schedule generator: https://crontab.guru/#0_3_*_*_*
# NB: To ensure pushes aren't rejected and to avoid conflicts,
# ensure you leave the repo on the correct branch and
# manually pull down changes pushed to the same branch.
@madsem

This comment has been minimized.

Copy link

commented Feb 23, 2019

Honestly think I will go this route, thanks for the gist :)
tried making Spock work all day today and it just won't work well for some reason. Will try your way

@wesort

This comment has been minimized.

Copy link
Owner Author

commented Aug 16, 2019

Example implementation using Scheduler in Laravel Forge

cd ~/example.com/ && ./autobackup.sh > /dev/null

cronjob-example-01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.