Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Creating backup using crontab

Joshua Taillon edited this page Jul 31, 2017 · 3 revisions

Save the following text in a script somewhere on your system (preferably as a .sh file):

#!/bin/sh
# Create folder with the date`
mkdir /tmp/$( date '+%Y-%m-%d' )

# Copy your file into the folder
cp /var/<Your file> /tmp/$( date '+%Y-%m-%d' )/<Your file>

# Goes to the tmp directory
cd /tmp/

# Creates a tar.gz file in the folder
tar -zcf $( date '+%Y-%m-%d' ).tar.gz $( date '+%Y-%m-%d' )

# Uses gdrive to upload file to Google Drive (change path to gdrive if necessary)
/usr/local/bin/gdrive upload $( date '+%Y-%m-%d' ).tar.gz

# Remove folder
rm -rf /tmp/$( date '+%Y-%m-%d' )

# Remove file
rm -rf /tmp/$( date '+%Y-%m-%d' ).tar.gz

To run in cron, add /bin/bash <your .sh file> to your crontab (varies by distro)

Clone this wiki locally