Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory)
and I am trying to copy files from the Documents directory to the new created directory that is unique. This will be in a crontab
backing up files from documents and when the backup will kick in, it will create new directory for each backup that is uniquely identified by the directory timestamp. For some reason I cannot get the cp
or cpio -mdp
.
bkdate="date +%Y_%m_%d_%H_%M_%S"
PATH=/home/user/backup/
bksource="/home/user/Documents/"
mkdir /home/user/backup/"bk$(date +%Y_%m_%d_%H_%M_%S)"
cp $bksource * ls | tail -l | $PATH
I could of went with the ctime
but unfortunately it does not work with the directory creation date.
This was my approach but with the latest created directory and not file
find $HOME -type d -daystart ctime 0
If someone could please help me out to copy to that new directory, I would really appreciate it.
Solution: This is one solution using target. I am open to other ways that could be used for this purpose.
bkdest=/home/user/backup
bksource=/home/user/Documents
target=${bkdest}/bk.$(date +%Y_%m_%d_%H_%M_%S)
mkdir -p $target
cp ${bksource}/* ${target}/
ctime
is metadata change time, NOT creation time