[SOLVED] consolidate backups using cp

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
JerryC58
Level 4
Level 4
Posts: 285
Joined: Sun Jul 14, 2013 7:02 pm
Location: West Des Moines, Iowa

[SOLVED] consolidate backups using cp

Post by JerryC58 »

Over the years I have made many backups of my Home directory. I am thinking of consolidating all of the Documents, Downloads etc directories to save space. So my idea is to create a new Documents directory, then copy files from all of the other Documents folders to the new one (unless they are duplicates), and then delete the old Documents folders.

I have studied man cp and I wonder if "cp -n /dir/*.* -t /dir" will do the job?

JC
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
JerryC58
Level 4
Level 4
Posts: 285
Joined: Sun Jul 14, 2013 7:02 pm
Location: West Des Moines, Iowa

Re: consolidate backups using cp

Post by JerryC58 »

Any ideas on this?

JC
User avatar
Boca
Level 5
Level 5
Posts: 691
Joined: Sun Feb 15, 2015 5:02 am

Re: consolidate backups using cp

Post by Boca »

JerryC58 wrote: Sun Apr 18, 2021 12:55 pm Any ideas on this?

JC

Personally, I would first run fslint to identify and remove duplicates ( if you're running 20.1, you'll have to install this .. see help I received in this thread viewtopic.php?f=90&t=346420)

If you're then using cp then would -u be better?
-u, --update Copy only when the source file is newer than the destination file or when the destination file is missing.

Rgds, Tony

PS do a dummy run on test files first.
User avatar
AndyMH
Level 21
Level 21
Posts: 13716
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: consolidate backups using cp

Post by AndyMH »

If I didn't use cp I'd probably use rsync. What are you going to use to find duplicates?
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
JerryC58
Level 4
Level 4
Posts: 285
Joined: Sun Jul 14, 2013 7:02 pm
Location: West Des Moines, Iowa

Re: consolidate backups using cp

Post by JerryC58 »

OK, here's where I'm at. My short term plan is to consolidate all the Document folders on my external backup drive. Using terminal, I figured out how to find that drive and get to the directories on it. I am attempting the first try using the following command to copy a Document folder to a new folder called merge: cp -u -r *.* /media/jc/01EF34E406892AF5/merge/Documents

The merge/Documents folder is empty. The copy appears to work, but when I check the destination, all I have is all of the individual files and 3 of 168 folders. Why isn't it getting all of the folders?
JC
User avatar
Boca
Level 5
Level 5
Posts: 691
Joined: Sun Feb 15, 2015 5:02 am

Re: consolidate backups using cp

Post by Boca »

I made the same set up
and found that

Code: Select all

cp -u -r *.* /media/jc/01EF34E406892AF5/merge/Documents
would not work at all as it returned "No such file or directory"
but by replacing *.* with * then it did work.

Hope that helps.
User avatar
AndyMH
Level 21
Level 21
Posts: 13716
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: consolidate backups using cp

Post by AndyMH »

Boca wrote: Tue Apr 20, 2021 2:46 pm but by replacing *.* with * then it did work.
You beat me to it :)
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
JerryC58
Level 4
Level 4
Posts: 285
Joined: Sun Jul 14, 2013 7:02 pm
Location: West Des Moines, Iowa

Re: consolidate backups using cp

Post by JerryC58 »

The suggestion of using * instead of *.* is working, but raises some more questions.
The option of -u to the cp command states that it will only copy a duplicate file if it is newer than the target file. How does it determine if the file is newer?
I found the --preserve option and it keeps the date modified intact. I hope that's the determining factor.

JC
User avatar
Boca
Level 5
Level 5
Posts: 691
Joined: Sun Feb 15, 2015 5:02 am

Re: consolidate backups using cp

Post by Boca »

JerryC58 wrote: Wed Apr 21, 2021 12:18 pm The suggestion of using * instead of *.* is working, but raises some more questions.
The option of -u to the cp command states that it will only copy a duplicate file if it is newer than the target file. How does it determine if the file is newer?
I found the --preserve option and it keeps the date modified intact. I hope that's the determining factor.

JC

My understanding is that this is the last time the file was modified.

Unless the files have been backed-up by a method which changes the modification date as part of the copy?? ( Now I'm asking a question.... :? )

Tony
Last edited by Boca on Wed Apr 21, 2021 2:08 pm, edited 1 time in total.
JerryC58
Level 4
Level 4
Posts: 285
Joined: Sun Jul 14, 2013 7:02 pm
Location: West Des Moines, Iowa

Re: consolidate backups using cp

Post by JerryC58 »

I'm moving along with my project. We'll know the answer later today or tomorrow.

JC
JerryC58
Level 4
Level 4
Posts: 285
Joined: Sun Jul 14, 2013 7:02 pm
Location: West Des Moines, Iowa

Re: consolidate backups using cp

Post by JerryC58 »

I believe the copy command we have come up with is doing the job. This will give me back quite a bit of space on my external drive. Thank you all for the help.

JC
Locked

Return to “Beginner Questions”