3

I have understood that is impossible to use dd or cat for copy all data of a partition to another partition with differences in sizes, Is this statement correct?, example

2 HDD, the first /dev/sdd1 (100gb), and used 30gb and the second /dev/sdc1 (50gb), and haven't data


Surely I cant use:
cat /dev/sdd1 >/dev/sdc1

why? Because sdd1 has partition of 100gb and sdc1 has limit of 50gb


Is it true? what should I use for copying?

could I use (Assuming that hdds are mounted):

cp -avr /mnt/sdd1/* /mnt/sdc1/

Is it correct to use cp? someone know to alternative to cp

EDIT: In case of cant mount hdd because linux not recognized partition, what could I do? Continue with this new question in: "Backup without free space in not recognized partition"

Note: I don't talking about of recovery tools like ddrescue

Thank you very much.

Milor123
  • 231
  • Yes you can, see here and here – George Udosen Dec 29 '16 at 15:32
  • @George Ty dude – Milor123 Dec 29 '16 at 16:00
  • @muru Nope, I don't need recovery disk – Milor123 Dec 29 '16 at 16:01
  • Who said anything about recovery disks? You have a faulty disk or corrupted partition tables, you need to do disk recovery, which has nothing to do with "recovery disks". – muru Dec 29 '16 at 16:02
  • 2
    Not sure what you are trying to do, but cp usually works best for copying files, as then you don't accidentally nuke the destination partition's filesystem (n.b. it is possible to have more than one partition on a disk). For recovery (when the filesystem can't be recognised or returns errors as it formatted incorrectly or the disk is not functioning correctly) in general you need to try to use the disk as little as possible, and carry out recovery operations on a copy - this is covered in @muru 's linked question, though I think there are others around this site too... – Wilf Dec 29 '16 at 16:54
  • I should add being patient is a good idea if you are recovering data as you may only have one or a few goes available to do it - checking the health of the disk for example using SMART data may also help (n.b. smart tests may take the disk offline while it is tested) – Wilf Dec 29 '16 at 17:02

3 Answers3

2

Sure, cp will work fine. You might have to use shopt -s dotglob so that * matches files and folders whose names begin with .:

shopt -s dotglob
cp -avr /mnt/sdd1/* /mnt/sdc1/

There's also rsync:

rsync -a --info=progress2 /mnt/sdd1/ /mnt/sdc1/

It has a nicer progress display.

muru
  • 197,895
  • 55
  • 485
  • 740
1

Please notice the difference of copying at the file level and cloning partitions or whole drives at the device level.

Copy files as described by muru

In this case you use the mounted partitions, where you see the directories and files.

rsync is a very good tool for backup and synchronizing.

Clone devices as described below

Cloning devices is very risky, and you must check and double-check, that you write to the correct device. Otherwise you might overwrite your family pictures ... and it is only a minor typing error away. When cloning you should unmount all partitions on the source and target devices. You already noticed that you should clone to a device of at least the same same.

sudo dd if=/dev/sdx of=/dev/sdy bs=4096

clones a device for example USB pendrive (from drive x to drive y).

sudo dd if=/dev/sdxm of=/dev/sdyn bs=4096

clones a partition to another partition (from partition xm to partition yn, where x and y are drive letters and m and n are partition numbers).

sudo dd if=/dev/sdx of=file.img bs=4096

creates an image file of a drive.

sudo dd if=/dev/sdx bs=4096 | xz > file.img.xz

creates a compressed image file.

sudo if=ubuntu.iso of=/dev/sdx bs=4096

creates a USB boot drive from an Ubuntu iso file.

-o-

It is possible to clone with cp instead of dd and get similar results.

Tools

In order to reduce the risk and to make the process easier for you, there are tools to help with this process, particularly to create boot drives from iso files and [compressed] image filas. Examples: the Ubuntu Startup Disk Creator (in 16.04 LTS and newer), Disks (gnome-disks), mkusb.

Clonezilla is a tools that can select the used blocks on the 'drive surface' and copy/clone them, while it skips the unused blocks. This makes cloning with Clonezilla much faster than cloning with dd (or cp), particularly, in a drive with a lot of free space.

sudodus
  • 46,324
  • 5
  • 88
  • 152
1

Firstly, the short version is no, and the reason being, you do not know where your data is on your first drive. It is almost certain that your data will not be in the first 30GB. This is something built into the linux filesystem, and the reason you never need to defrag; ie. your data is randomly allocated into the free space, the opposite of your old MSDOS days of having to defrag once a week.

I don't have the reputation points to adjust the one commend above, but your quickest way of achieving what you need is this:

rsync -avz --delete /mnt/sdd1 /mnt/sdc1

The -r is not necessary, as -a automatically implies -r too. I have included descriptions of the switches:

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)

--delete delete extraneous files from destination dirs

-z, --compress compress file data during the transfer

You may choose to neglect -z, however I find it very handy for network copies, especially Wi-Fi.

For the repair, have you tried fsck?

I found another tool called TestDisk from http://www.cgsecurity.org/, but you're required to have at least that amount of space available that you're wanting to recover.

wjandrea
  • 14,236
  • 4
  • 48
  • 98