Compare commits
10 Commits
67906a920a
...
ee8c693f3b
Author | SHA1 | Date | |
---|---|---|---|
ee8c693f3b | |||
|
b7c052b39a | ||
b65901c151 | |||
2cb8f3cc7f | |||
0ca6ba656d | |||
3063272f1f | |||
1dad5cda13 | |||
a1e80eb09a | |||
b9f7caabe1 | |||
098d6d1c44 |
4
Makefile
4
Makefile
@ -3,14 +3,14 @@ DESTDIR ?=
|
|||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
# Build flags
|
# Build flags
|
||||||
FLAGS = -std=gnu99
|
OPTS = -std=gnu99
|
||||||
|
|
||||||
# Build rules
|
# Build rules
|
||||||
all: backly
|
all: backly
|
||||||
.PHONY: all install clean
|
.PHONY: all install clean
|
||||||
|
|
||||||
backly: backly.c Makefile
|
backly: backly.c Makefile
|
||||||
gcc $(FLAGS) -o backly backly.c
|
gcc $(OPTS) $(CFLAGS) -o backly backly.c
|
||||||
|
|
||||||
install: backly
|
install: backly
|
||||||
install -Dm 0755 backly $(DESTDIR)/$(PREFIX)/bin/backly
|
install -Dm 0755 backly $(DESTDIR)/$(PREFIX)/bin/backly
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
About backly
|
# backly
|
||||||
============
|
|
||||||
|
A simple directory cloner
|
||||||
|
|
||||||
|
## About backly
|
||||||
|
|
||||||
backly is a simple rsync-like tool for recursively copying entire directories.
|
backly is a simple rsync-like tool for recursively copying entire directories.
|
||||||
The intended use case is for making verionless incremental backups; however, it
|
The intended use case is for making verionless incremental backups; however, it
|
||||||
@ -8,31 +11,25 @@ provided you have read access to the source and write access to the
|
|||||||
destination. Like rsync, backly uses a combination of file size and
|
destination. Like rsync, backly uses a combination of file size and
|
||||||
modification date to determine if it needs to be copied over.
|
modification date to determine if it needs to be copied over.
|
||||||
|
|
||||||
This program will not work properly if source is a subdirectory
|
This program will **not** work properly if source is a subdirectory
|
||||||
or destination or vice-versa.
|
or destination or vice-versa.
|
||||||
|
|
||||||
|
## Required packages
|
||||||
Required packages
|
|
||||||
=================
|
|
||||||
|
|
||||||
backly does not depend on any packages other than what typically ships with any
|
backly does not depend on any packages other than what typically ships with any
|
||||||
Linux distribution.
|
Linux distribution.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
Installation
|
The usual `make` and `make install` is sufficient for compiling and installing
|
||||||
============
|
backly. The default prefix is `/usr/local`, which means the binary will be
|
||||||
|
installed to `/usr/local/bin`. The prefix can be changed by setting it in the
|
||||||
|
install command; for example, by running `make PREFIX=/usr install`.
|
||||||
|
|
||||||
The usual 'make' and 'make install' is sufficient for compiling and installing
|
## How to report bugs?
|
||||||
backly. The default prefix /usr/local, which means the binary will be installed
|
|
||||||
to /usr/local/bin. The prefix can be changed by setting it in the install
|
|
||||||
command; for example, by running 'make PREFIX=/usr install'.
|
|
||||||
|
|
||||||
|
Open an issue on the issue tracker.
|
||||||
How to report bugs?
|
|
||||||
===================
|
|
||||||
|
|
||||||
Bugs should be reported to L. Bradley LaBoon <me@bradleylaboon.com>
|
|
||||||
|
|
||||||
Please indicate what OS and architecture you are using, as well as output from
|
Please indicate what OS and architecture you are using, as well as output from
|
||||||
the program showing the bug, if possible (hint: run backly with --test to avoid
|
the program showing the bug, if possible (hint: run backly with `--test` to
|
||||||
destroying any files that you care about).
|
avoid destroying any files that you care about).
|
17
backly.c
17
backly.c
@ -39,8 +39,9 @@ void printHelp()
|
|||||||
printf("Turn destdir into a clone of srcdir.\n\n");
|
printf("Turn destdir into a clone of srcdir.\n\n");
|
||||||
|
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" --test\tRun in test mode.\n");
|
printf(" --test\t\tRun in test mode\n");
|
||||||
printf(" --help\tPrint this help and quit.\n\n");
|
printf(" --noremove\tDon't remove any files in destdir\n");
|
||||||
|
printf(" --help\t\tPrint this help and quit\n\n");
|
||||||
|
|
||||||
printf("Report bugs to L. Bradley LaBoon <me@bradleylaboon.com>\n");
|
printf("Report bugs to L. Bradley LaBoon <me@bradleylaboon.com>\n");
|
||||||
printf("backly home page: <http://git.bradleylaboon.com/backly.git>\n");
|
printf("backly home page: <http://git.bradleylaboon.com/backly.git>\n");
|
||||||
@ -267,7 +268,7 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
|
|||||||
fprintf(stderr, "Could not fork: %s\n", strerror(errno));
|
fprintf(stderr, "Could not fork: %s\n", strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
} else if (pid == 0) {
|
} else if (pid == 0) {
|
||||||
execlp("cp", "cp", "-fp", itemSrc, itemDest, (char *) NULL);
|
execlp("cp", "cp", "-f", "-P", "--preserve=timestamps,links", itemSrc, itemDest, (char *) NULL);
|
||||||
} else {
|
} else {
|
||||||
struct stat srcStat, destStat;
|
struct stat srcStat, destStat;
|
||||||
double pDone = 0;
|
double pDone = 0;
|
||||||
@ -283,8 +284,13 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
|
|||||||
printf("\b \b");
|
printf("\b \b");
|
||||||
numPrinted = printf("%.2lf%%", pDone * 100);
|
numPrinted = printf("%.2lf%%", pDone * 100);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
usleep(50000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < numPrinted; i++)
|
||||||
|
printf("\b \b");
|
||||||
|
printf("100.00%%");
|
||||||
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -299,7 +305,7 @@ void copyNew(char *src, int srcPrefix, char *dest, int destPrefix, int testMode)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int srcArg = 0, destArg = 0;
|
int srcArg = 0, destArg = 0;
|
||||||
int testMode = 0;
|
int testMode = 0, remove = 1;
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
@ -309,6 +315,8 @@ int main(int argc, char **argv)
|
|||||||
} else if (strcmp(argv[i], "--test") == 0) {
|
} else if (strcmp(argv[i], "--test") == 0) {
|
||||||
testMode = 1;
|
testMode = 1;
|
||||||
printf("***Operating in test mode.***\n");
|
printf("***Operating in test mode.***\n");
|
||||||
|
} else if (strcmp(argv[i], "--noremove") == 0) {
|
||||||
|
remove = 0;
|
||||||
} else if (srcArg == 0) {
|
} else if (srcArg == 0) {
|
||||||
srcArg = i;
|
srcArg = i;
|
||||||
} else {
|
} else {
|
||||||
@ -358,6 +366,7 @@ int main(int argc, char **argv)
|
|||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
// Remove files from the destination that don't exist in the source
|
// Remove files from the destination that don't exist in the source
|
||||||
|
if (remove)
|
||||||
removeMissing(srcDir, strlen(srcDir), destDir, strlen(destDir), testMode);
|
removeMissing(srcDir, strlen(srcDir), destDir, strlen(destDir), testMode);
|
||||||
|
|
||||||
// Copy new files and overwrite existing files if different
|
// Copy new files and overwrite existing files if different
|
||||||
|
Loading…
Reference in New Issue
Block a user