如果内容发生了变化,是否可以复制文件以实现简单的版本控制?
myFolderInclSubfolderBackupWithVersioning.sh < source folder> < dest >
例如源文件夹
- file1.jpg 100K(今天)
目标上的文件夹,例如外部硬盘:
- file1.jpg 大小 100K(今天)
- file1(2).jpg 大小 99K (昨天)
- file1(1).jpg 大小 101K (2个月前)
谢谢你!
答案1
以下设置有效:
- 工作目录
work
(可以有子目录) - 工作目录旁边的备份目录
backup
(在实际情况下,您可能将备份目录放在外部驱动器中)
此命令将从 备份work
到backup
:
cp -r --backup=t work/* backup/
例子
$ find
.
./work
./work/file:name
./work/foo.sh
./work/file-0
./work/dollarfraga1
./work/dollarfraga2
./work/sub
./work/sub/hello
./work/dollarfraga
./backup
$ cp -r --backup=t work/* backup/
$ find
.
./work
./work/file:name
./work/foo.sh
./work/file-0
./work/dollarfraga1
./work/dollarfraga2
./work/sub
./work/sub/hello
./work/dollarfraga
./backup
./backup/file:name
./backup/foo.sh
./backup/file-0
./backup/dollarfraga1
./backup/dollarfraga2
./backup/sub
./backup/sub/hello
./backup/dollarfraga
$ cp -r --backup=t work/* backup/
$ find
.
./work
./work/file:name
./work/foo.sh
./work/file-0
./work/dollarfraga1
./work/dollarfraga2
./work/sub
./work/sub/hello
./work/dollarfraga
./backup
./backup/file:name
./backup/dollarfraga1.~1~
./backup/foo.sh
./backup/dollarfraga.~1~
./backup/file-0
./backup/file:name.~1~
./backup/dollarfraga1
./backup/dollarfraga2.~1~
./backup/file-0.~1~
./backup/dollarfraga2
./backup/sub
./backup/sub/hello
./backup/sub/hello.~1~
./backup/dollarfraga
./backup/foo.sh.~1~
$ cp -r --backup=t work/* backup/
$ find
.
./work
./work/file:name
./work/foo.sh
./work/file-0
./work/dollarfraga1
./work/dollarfraga2
./work/sub
./work/sub/hello
./work/dollarfraga
./backup
./backup/file:name
./backup/foo.sh.~2~
./backup/dollarfraga1.~1~
./backup/file-0.~2~
./backup/foo.sh
./backup/file:name.~2~
./backup/dollarfraga1.~2~
./backup/dollarfraga2.~2~
./backup/dollarfraga.~1~
./backup/file-0
./backup/dollarfraga.~2~
./backup/file:name.~1~
./backup/dollarfraga1
./backup/dollarfraga2.~1~
./backup/file-0.~1~
./backup/dollarfraga2
./backup/sub
./backup/sub/hello
./backup/sub/hello.~2~
./backup/sub/hello.~1~
./backup/dollarfraga
./backup/foo.sh.~1~
可以cp
这样使用,但我建议您学习rsync
,这是一个更高级的工具,用于复制目录结构(包括备份),或者可能是一些专用的备份工具。rsync
而其他工具只会复制新的或已更改的文件。