Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to auto backup specific files to specific flash dr?

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
loganmac
Posts: 30
Joined: 2009-11-03 03:37

How to auto backup specific files to specific flash dr?

#1 Post by loganmac »

Okay, I'm a bit of a noob, so forgive me but I don't know what I'm doing here. I blundered and lost some data, and so now I'm looking at an easy way to back up the important stuff.

I have a bunch of pictures and music files on my system, but those don't require as frequent backups. I have a 2GB flash drive that has plenty of room to hold everything. Here is what I'd like to do, if it is possible:

1. Any user plugs in a specific 2GB flash.thumb drive. (I don't want any flash drive initiating this event, just the specific one.)
2. The device is mounted
3. The device gets a copy of everything in the /home directory that is not a picture or music file, overwriting any previous backup
4. The device us unmounted
5. A message showing the backup is complete pops onto the screen.


Is there a way to do this, or something similar? If I could do this, I could plug in the flash every day to make sure the important stuff was backed up, doing a more extensive backup periodically.

fsmithred
Posts: 1873
Joined: 2008-01-02 14:52

Re: How to auto backup specific files to specific flash dr?

#2 Post by fsmithred »

On item #3, is there some reason why it has to overwrite, or would you be happy with just writing the changes? You can do incremental and highly selective backups with rsync. There are gui frontends that you could use, like lucky backup or another whose name I can't remember. (I think there were several named in a recent thread about backups.)

The part about having it go automatically when you plug in a specific drive sounds complicated. You might have to resign yourself to opening the program manually and clicking a button when you know you have the right drive in. At least for awhile.

fsmithred
Posts: 1873
Joined: 2008-01-02 14:52

Re: How to auto backup specific files to specific flash dr?

#3 Post by fsmithred »

This thread might be helpful for what you want to do to automate the procedure:
http://forums.debian.net/viewtopic.php?f=5&t=48833
It's not exactly beginner stuff.

If you could backup to a drive that's always connected, either to your computer or across a network to another computer, you could just set the backup program to run at certain times or set up rsync to run as a cron job. But then you'd miss out on the fun of writing a udev rule.

loganmac
Posts: 30
Joined: 2009-11-03 03:37

Re: How to auto backup specific files to specific flash dr?

#4 Post by loganmac »

Well, writing a UDEV stuff looks well beyond my limited capabilities. Doing it on insertion I understand is complicated, and I can let go of that. Is there a way to do something, like a script or something, so that I can do something from the xterm? Maybe I could have 1 script for the daily backup (without pictures or music files), and 1 script for a full backup (including everything). I only need to backup the /home directory.

Thoughts? Is there a simple way to do this? I couldn't find "lucky backup" in the package list on Debian so I'm not sure which package to apt-get. Thanks...

fsmithred
Posts: 1873
Joined: 2008-01-02 14:52

Re: How to auto backup specific files to specific flash dr?

#5 Post by fsmithred »

I wrote the name wrong for you the first time. No space.
~$ aptitude search lucky
p luckybackup - rsync-based GUI data backup utility
p luckybackup-data - rsync-based GUI data backup utility (data

Code: Select all

aptitude search ~dbackup
Will list every package in the repository that has the word backup in its description. I see some in the list that other people have recommended on this forum, such as bacula, rsnapshot, keep, backintime (kde and gnome versions). Maybe search for screenshots of these to get an idea of which you'd like to try.

If you want to go with command line, writing a script to execute a single rsync command would be easy, and you could have as many as you wanted for different kinds of backups. Getting the rsync command is a little trickier, but it's not too bad. Take a look at man rsync and some of the other rsync discussions before you try this, but here's what I use.

Code: Select all

rsync -avx --delete --exclude-from=.rsync/excludes /source /destination
One of the trickier parts of rsync is understanding the concept of the root of the file transfer. Skip to the end of man rsync to read about it. Put simply, rsync copies everything to the right of the last slash in your source path. So if your do

Code: Select all

rsync -avx /home/user/  /media/backup-drive/user/
you'll end up with all your files and directories in /media/backup-drive/user, but if you do

Code: Select all

rsync -avx /home/user  /media/backup-drive/user/
you'll end up with everything in /media/backup-drive/user/user.

The excludes file can look something like this

Code: Select all

- /Multimedia/
- /Multimedia/
- .Trash
- .thumbnails
- */Cache/
Instead of excluding things, you could include things, and I'm pretty sure you can use wildards, like *.jpg or *.mp3.

Go play with that and report back or ask more questions.

Scripting it is easy.

Code: Select all

#!/bin/bash
rsync --whatever-options /source /destination
exit 0
Make it executable, put it in /home/user/bin and call it by name. One possible problem is if your external drive doesn't get the same name every time you plug it in. I think that could be fixed by giving the disk a label.

User avatar
Absent Minded
Posts: 3464
Joined: 2006-07-09 08:50
Location: Washington State U.S.A.
Been thanked: 3 times

Re: How to auto backup specific files to specific flash dr?

#6 Post by Absent Minded »

loganmac wrote:Okay, I'm a bit of a noob, so forgive me but I don't know what I'm doing here. I blundered and lost some data, and so now I'm looking at an easy way to back up the important stuff.

I have a bunch of pictures and music files on my system, but those don't require as frequent backups. I have a 2GB flash drive that has plenty of room to hold everything. Here is what I'd like to do, if it is possible:

1. Any user plugs in a specific 2GB flash.thumb drive. (I don't want any flash drive initiating this event, just the specific one.)
2. The device is mounted
3. The device gets a copy of everything in the /home directory that is not a picture or music file, overwriting any previous backup
4. The device us unmounted
5. A message showing the backup is complete pops onto the screen.


Is there a way to do this, or something similar? If I could do this, I could plug in the flash every day to make sure the important stuff was backed up, doing a more extensive backup periodically.
If you are using KDE it supports the ability to use an "Autorun" file of sorts in the root diretory of removable media. You could write a script that would then run when your USB device is incerted. Although I am not firilyer with writing Linux scripts the basic idea would go something like this:


cp -a /home/user/myfilesA /media/usb0
cp -a /home/user/myfilesB /media/usb0
kdesu umount /media/usb0 (or just remove the usb device)

KDE will auto mount the device when it is incerted, read the "Autorun" script perform the script tasks and then unmount the device after you supply your root password.
Serving the community the best way I can.
Spreading the tradition of Community Spirit.
Please read some Basic Forum Philosophy
Give a man a fish, he eats for a day. Teach him how to fish, he eats for life.
Updated Nov. 19, 2012

User avatar
nadir
Posts: 5961
Joined: 2009-10-05 22:06
Location: away

Re: How to auto backup specific files to specific flash dr?

#7 Post by nadir »

Code: Select all

 the basic idea would go something like this:


cp -a /home/user/myfilesA  /media/usb0
cp -a /home/user/myfilesB  /media/usb0
kdesu umount /media/usb0 (or just remove the usb device)
i bet a bug thats pretty much the whole script. with the shebang at the beginning and the exit 0 at the end. not sure about the kdesu, but i have seen an awesome script (xsystemcopy) which (basically) is just like that: a summary of commands (that is: no "while", no "if-else", no "for", no nothing like that. just commands) i would just try it that way.

or:perhaps someone might offer it with all the bells and whistles.
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.

Post Reply