Giter Site home page Giter Site logo

backup-script's Introduction

Backup script

A shell script for backing up your files.


The story

I love Mac's TimeMachine, it automatically backs up my files, but for some reason I'm not using it in my working laptop, so I created a simple shell script for backing up my data in my working laptop.

Usage

This script accepts three parameters:

  1. Target folder/file you want to backup.
  2. Destination folder you want to store your backups.
  3. Maximum days for keeping your backups, if you set it to 10, this script will delete all your backups in 10 days ago.

Example:

./backup.sh ~/Projects/Demo ~/Dropbox/Backups 10

It will compress the ~/Projects/Demo folder to a single tar.gz file and store it in ~/Dropbox/Backups then delete all the backups in 10 days ago.

Scheduled backups

We can use launchd(macOS) or cron(Linux) to backup our data in a specific time.

Assume we want automatic backup ~/Project to ~/Dropbox/Backups at 10:00PM in every day.

launchd(macOS)

1. Create a launchd config file for this task.

Save the following code snippet as com.tonni.BackupProjectsToDropbox.plist in ~/Library/LaunchAgents/.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.tonni.BackupProjectsToDropbox</string>
    <key>LowPriorityIO</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/Tonni/.Backup-script/backup.sh</string>
        <string>/Users/Tonni/Project</string>
        <string>/Users/Tonni/Dropbox/Backups</string>
        <string>3</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Hour</key>
            <integer>22</integer>
            <key>Minute</key>
            <integer>00</integer>
        </dict>
    </array>
</dict>
</plist>

Note:

  • Use absolute path in config file.
  • Keep the Label value and the filename alike.

2. Load the new launchd config.

$ launchctl load com.tonni.BackupProjectsToDropbox.plist.

Cron(Linux)

Open your cron config file: $ crontab -e and append the following line in the config file:

0 22 * * * /home/tonni/.Backup-script/backup.sh /home/tonni/Project /home/tonni/Dropbox 3 >> /tmp/backup.log

LICENSE

Do What the Fuck You Want to Public License

backup-script's People

Contributors

houcoder avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.