0

I've got a situation where I need to give some people access to my dropbox folder. Already so far they have deleted huge folders full of important data. Their computer skills could use a bit of work, apparently. Thankfully there is a restore function on the dropbox website. But the gui doesn't seem super-powerful, and I'm afraid that these people are going to permanently delete something.

I've been making a zip archive of the folder, and saving it every day on my local machine. I've already restored files on it that I couldn't find on the dropbox restore gui.

But I'm afraid that I'll get busy or lazy and forget to make the archive. So I figure that this is a good opportunity to learn basic automated shell scripting.

How can I design a script that will

  1. Run on startup
  2. Prompt me (I don't know how) to see if I want to make a zip archive of a specific directory
  3. Do so, and save it as /path/to/archives/<date>

??

I know only minimal bash at present (cd, ls, ssh, etc), so a working example of how to do such a thing would be a springboard to doing other useful similar things in the future.

I'm running Ubuntu on a thinkpad x230.

2
  • May be you are looking for cron.Look at man page of the cron – Thushi Aug 26 '14 at 11:42
  • If you shutdown and reboot your machine every day, or even logout and login the next day, consider putting the command into your .profile or some other file that gets processed on login. – G-Man Says 'Reinstate Monica' Aug 26 '14 at 19:38
1

You should use crontab

Example:

If you wished to have a script named tarBackup.sh run every day at 5am, your crontab entry would look like as follows.

First, install your cronjob by running the following command:

crontab -e

Append the following entry:

0 5 * * * xterm -e /path/to/tarbackup.sh

Save and close the file.

Your tarBackup.sh

Your tarBackup.sh should have the following lines.

#!/bin/bash
echo "Do you wan to backup?(yes/no)"
read input
if [ "$input" == "yes" ] 
then
    tar -cvf dir.tar dir1 dir2
else
    echo "K sir,I won't backup anything"
fi

[An example,Edit the tar command however you want]

The general syntax for crontab is as follows.

1 2 3 4 5 /path/to/some/command

where

1: Minutes 0-59
2: Hours in 24 hours format
3: Day 0-31
4: Month 0-12
5: Day of the week 0-7
/path/to/some/command - Command or script name to schedule
4
  • 2
    It's a bad idea to put an interactive script as a cron job. – Leiaz Aug 26 '14 at 18:24
  • @Leiaz: Yeah.But If OP is so sure about providing input at the right time then no need to worry at all. :) – Thushi Aug 27 '14 at 5:19
  • Thanks - this is a bit over my head, but I'll work through it. I don't understand the cron interface yet, nor have I figured out how to make the archive via the terminal. Shell scripts in the .profile directory get run on startup? – generic_user Aug 27 '14 at 6:50
  • @ACD: If you put it in .profile it executes every time you login.[you can't run that periodically].Say,If you haven't shutdown your system for 1 month then you can't backup your data for one month.You can remove asking input from the user that is read in your tarbackup.sh and let it tar your important files every day through cron job. – Thushi Aug 27 '14 at 7:05
1

I don't know why you want to use ziped files for your backup.

If you use rsync, you will be able to only backup new and changed files (removed files is not affected).

Example:

#!/bin/bash
# see http://ss64.com/bash/rsync_options.html
DROPBOX=~/Dropbox/
BACKUP=~/dropboxbackup

rsync -rvt $DROPBOX $BACKUP

The flags:

r - recursive

v - verbose

t - preserve times

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.