2

I have a little bash script going to check if the system has been backed up today and and if it hasn't then it copies the entire filesystem into the backups folder:

date=$(date +"%m%d%y")
sudo mkdir -p "/backups/system/$date"
sudo cp -r "/" "/backups/system/$date"

My problem is that when I enter this it gives me these errors:

cp: error reading ‘/proc/1/task/1/mem’: Input/output error
cp: failed to extend ‘/backups/system/040315/proc/1/task/1/mem’: Input/output error
cp: error reading ‘/proc/1/task/1/clear_refs’: Invalid argument
cp: failed to extend ‘/backups/system/040315/proc/1/task/1/clear_refs’: Invalid argument

2 Answers2

7

In Linux everything is a file

(That does not mean you can back them up)

Technically everything is not files (I am no expert). However, some folders are special in the sense that they are not real folders. /proc is just one of them. It is a virtual file system that contains runtime file information. In other words, its contents keep changing as the system runs. You should not try to back it up.

Other such folders are /sys, /mnt, /media, /run and /dev . /sys like /proc is another virtual filesystem that provide windows into variables of the running kernel, so you do not want to try and backup or restore them. /dev is a tmpfs whose contents are created and deleted dynamically by udev, so you also do not want to backup or restore it. Likewise, /run is a tmpfs that holds variables about the running system that do not need backed up. This paragraph is adapted from Backup Your System/TAR.

In general copying / is not a good idea. Note, /backups/system/$date is also a part of /. So you may end up baking up the backup till kingdom come, or you run out of disk space.

Hope This helps

user68186
  • 37,461
2

Ignore them. You're trying to copy files from /proc which is both pointless and won't work, as you saw. Those are basically runtime files vreated by the OS. There's no need or reason to have backups of such files.

So, the simple approach is to just ignore the errors. You can also stop them appearing by redirecting error output to /dev/null:

sudo cp -r / "/backups/system/$date" 2>/dev/null

A more sophisticated approach would be to specify the directories you want to copy. For example:

sudo cp -r /lib /usr /mnt /bin /opt /lib64 /tmp /home /sbin /media /etc /root  /boot /var "/backups/system/$date"

Those are the ones you care about. You probably don't need /mnt or /media either.

terdon
  • 104,119