Skip to content

Commit

Permalink
Fixed #14 All partitions are now backed up. Adjust your black-/whitel…
Browse files Browse the repository at this point in the history
…ists! Partition numbers are now added to the back of the device identifier.

Also replaced some \ts with four spaces.
  • Loading branch information
TacoSteemers committed Apr 13, 2013
1 parent 4d0702b commit 4e89430
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 134 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ usbud
===== =====


## USB Storage Back Up Daemon ## USB Storage Back Up Daemon
The daemon will back up USB storage devices the moment they are plugged in. The daemon will back up all mounted partitions on USB storage devices.
The daemon supports blacklisting and whitelisting. Either list consists of a file that contains one device id on each line. One can use the 'uslist' executable to find the device ids. The daemon supports per-partition blacklisting and whitelisting. Either list consists of a file that contains one device id on each line. One can use the 'uslist' executable to find the device ids.
Log output can be found in syslog. Log output can be found in syslog.
This project is known to work on GNU/Linux systems. usbud depends on the availability of items such as '/sys/block' and '/proc/mounts' and the application 'rsync'. This project is known to work on GNU/Linux systems. usbud depends on the availability of items such as '/sys/block' and '/proc/mounts' and the application 'rsync'.
**Important note: the USB storage back up daemon should not be confused with a 'full' backup solution. It should be used in conjunction with a 'full' backup solution.** **Important note: the USB storage back up daemon should not be confused with a 'full' backup solution. It should be used in conjunction with a 'full' backup solution.**
Expand Down Expand Up @@ -31,17 +31,18 @@ Please note that re-inserting a device, even in a different slot, does not neces


Here are some examples of identifiers: Here are some examples of identifiers:


Generic MultiCard Device 00000000000006 USB SD Reader Generic MultiCard Device 00000000000006 USB SD Reader1
InphiCHN Mass Storage Device USB Flash Disk InphiCHN Mass Storage Device USB Flash Disk1
Kingston DataTraveler 2.0 899000000000000000000073 DataTraveler 2.0 Kingston DataTraveler 2.0 899000000000000000000073 DataTraveler 2.01
Kingston DataTraveler 2.0 899000000000000000000094 DataTraveler 2.0 Kingston DataTraveler 2.0 899000000000000000000094 DataTraveler 2.01
Kingston DataTraveler 2.0 8998011620080115142551D9 DataTraveler 2.0 Kingston DataTraveler 2.0 8998011620080115142551D9 DataTraveler 2.01
Generic Mass Storage 0ABE6A52 Flash Disk Generic Mass Storage 0ABE6A52 Flash Disk1
Apple iPod 000A27001CB7AFED iPod Generic Mass Storage 0ABE6A52 Flash Disk2
Apple iPod 000A27001CB7AFED iPod1


The first is a card that has been inserted in an 'all-in-one' card reader. This is supported. You may encounter problems when you use several card readers that were created by the same manufacturer. Maybe they would have to be of the same model, before problems occur. The first is a card that has been inserted in an 'all-in-one' card reader. This is supported. You may encounter problems when you use several card readers that were created by the same manufacturer. Maybe they would have to be of the same model, before problems occur.
The second is a cheap thumb drive that does not carry any identifying meta data at all. If you plug in a second one that was made by the same manufacturer, the daemon system will become confused. Most likely it will remove the backup that it has for the first drive, and place the backup of the second drive in it's stead. The second is a cheap thumb drive that does not carry any identifying meta data at all. If you plug in a second one that was made by the same manufacturer, the daemon system will become confused. Most likely it will remove the backup that it has for the first drive, and place the backup of the second drive in it's stead.
The next four items are regular thumb drives that will work quite well. The next five items are regular thumb drives that will work quite well. One of them has two partitions on it.
The last item is an iPod shuffle. Not every audio device is supported. To the best of my knowledge, all Creative Zen devices are not and are unlikely to ever be supported, because they use the 'MTP' protocol (Media Transfer Protocol). I have a Zen that I have tested this with. MTP is related to the Picture Transfer Protocol, and as such I'm quite certain that PTP devices are not supported either. The last item is an iPod shuffle. Not every audio device is supported. To the best of my knowledge, all Creative Zen devices are not and are unlikely to ever be supported, because they use the 'MTP' protocol (Media Transfer Protocol). I have a Zen that I have tested this with. MTP is related to the Picture Transfer Protocol, and as such I'm quite certain that PTP devices are not supported either.


## Notes on device labels and multi-card readers ## Notes on device labels and multi-card readers
Expand Down
2 changes: 1 addition & 1 deletion code/backup.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "bookKeeping.h" #include "bookKeeping.h"
#include "backup.h" #include "backup.h"


void processDevice(char* mountPoint, char* deviceId) void perhapsPerformBackup(char* mountPoint, char* deviceId)
{ {
int index; int index;
if(checkIfDeviceIsKnown(deviceId)==1) if(checkIfDeviceIsKnown(deviceId)==1)
Expand Down
2 changes: 1 addition & 1 deletion code/backup.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef BACKUP_H #ifndef BACKUP_H
#define BACKUP_H #define BACKUP_H


void processDevice(char *mountPoint, char *deviceId); void perhapsPerformBackup(char *mountPoint, char *deviceId);
int needsBackup(char* deviceId); int needsBackup(char* deviceId);
void createTargetDirectoryString(char* output, char* deviceId); void createTargetDirectoryString(char* output, char* deviceId);
void doBackup(char *source, char *target); void doBackup(char *source, char *target);
Expand Down
122 changes: 61 additions & 61 deletions code/bookKeeping.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,81 +14,81 @@ device* devices[MAXNUMDEVS];


void initializeDeviceBookKeeping(void) void initializeDeviceBookKeeping(void)
{ {
int i = 0; int i = 0;
for(; i < MAXNUMDEVS; i++) for(; i < MAXNUMDEVS; i++)
{ {
devices[i] = malloc(sizeof(device)); devices[i] = malloc(sizeof(device));
if(!devices[i]) if(!devices[i])
{ {
syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization"); syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
devices[i]->index = i; devices[i]->index = i;
devices[i]->runId = 0; devices[i]->runId = 0;
devices[i]->id = malloc(sizeof(char) * 256); devices[i]->id = malloc(sizeof(char) * 256);
if(!devices[i]->id) if(!devices[i]->id)
{ {
syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization"); syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
devices[i]->id[0] = '\0'; devices[i]->id[0] = '\0';
} }
} }


void initializeRun(void) void initializeRun(void)
{ {
/* Ensure that the previous gCurrentRunId is different /* Ensure that the previous gCurrentRunId is different
from the current, and is not equal to zero. */ from the current, and is not equal to zero. */
gCurrentRunId += 1; gCurrentRunId += 1;
if(gCurrentRunId > 2) if(gCurrentRunId > 2)
{ {
gCurrentRunId = 1; gCurrentRunId = 1;
} }
} }


void finalizeRun(void) void finalizeRun(void)
{ {
int i = 0; int i = 0;
/* Here we will remove stale data from bookkeeping */ /* Here we will remove stale data from bookkeeping */
for(; i < MAXNUMDEVS; i++) for(; i < MAXNUMDEVS; i++)
{ {
if(devices[i]->id[0] == 0) if(devices[i]->id[0] == 0)
continue; /* No data, no need to remove */ continue; /* No data, no need to remove */
if(devices[i]->runId == gCurrentRunId) if(devices[i]->runId == gCurrentRunId)
continue; /* Recent data, no need to remove */ continue; /* Recent data, no need to remove */
syslog(LOG_INFO, "Removing stale device \"%s\".", devices[i]->id); syslog(LOG_INFO, "Removing stale device \"%s\".", devices[i]->id);
devices[i]->id[0] = '\0'; devices[i]->id[0] = '\0';
devices[i]->runId = 0; devices[i]->runId = 0;
} }
} }


int checkIfDeviceIsKnown(char* deviceId) int checkIfDeviceIsKnown(char* deviceId)
{ {
int i = 0; int i = 0;
for(; i < MAXNUMDEVS; i++) for(; i < MAXNUMDEVS; i++)
{ {
if(strncmp(devices[i]->id, deviceId, strlen(deviceId)) != 0) if(strncmp(devices[i]->id, deviceId, strlen(deviceId)) != 0)
continue; /* Not the same */ continue; /* Not the same */
/* This is the same. We will update the runId, /* This is the same. We will update the runId,
to show that this device is not stale */ to show that this device is not stale */
devices[i]->runId = gCurrentRunId; devices[i]->runId = gCurrentRunId;
return 1; return 1;
} }
return 0; return 0;
} }


int registerDevice(char* deviceId) int registerDevice(char* deviceId)
{ {
int i = 0; int i = 0;
for(; i < MAXNUMDEVS; i++) for(; i < MAXNUMDEVS; i++)
{ {
if(devices[i]->id[0] != '\0') if(devices[i]->id[0] != '\0')
continue; /* Not an empty spot */ continue; /* Not an empty spot */
memcpy(devices[i]->id, deviceId, strlen(deviceId)+1); memcpy(devices[i]->id, deviceId, strlen(deviceId)+1);
devices[i]->runId = gCurrentRunId; devices[i]->runId = gCurrentRunId;
syslog(LOG_INFO, "Device \"%s\" has been registered.", deviceId); syslog(LOG_INFO, "Device \"%s\" has been registered.", deviceId);
return i; return i;
} }
syslog(LOG_INFO, "Device \"%s\" could not be registered. Too many devices have been registered already.", deviceId); syslog(LOG_INFO, "Device \"%s\" could not be registered. Too many devices have been registered already.", deviceId);
return -1; return -1;
} }
Loading

0 comments on commit 4e89430

Please sign in to comment.