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
    I can see a couple of potential issues. As /backups is a subdirectory of /, then the backups directory itself will be included in the backup. Also, /proc doesn't contain any actual files, it holds virtual files used by the system as it runs; you don't need or even want to be making backups of those. – Carl H Apr 03 '15 at 15:18
  • 6
    That is not the best of backup strategies. See https://help.ubuntu.com/community/BackupYourSystem and https://help.ubuntu.com/community/BackupYourSystem/TAR – Panther Apr 03 '15 at 15:20
  • many of the problems with your backup strategy are discussed in detail in the second link I gave you. – Panther Apr 03 '15 at 15:21
  • Better to make errors when trying to back up then not to make any back-ups at all! ;-) Have a look here for a good back-up strategy – Fabby Apr 08 '15 at 20:41

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
  • 33,360
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
  • 100,812
  • consider using tar with compression and list directories to exclude . The archive will be compressed. http://www.aboutdebian.com/tar-backup.htm – Panther Apr 03 '15 at 15:27
  • @bodhi.zazen good point but the OP might want to keep the files separate and uncompressed. – terdon Apr 03 '15 at 15:28
  • 2
    True, but cp and tar make very large size backups most of which are IMO unecessary. After many years I only back up user data in /home any system file I edited in /etc, any custom files in /usr/local, and any server data such as FTP/samba shares/ or /var/www depending on if I am running a server. Everything else is available in a .deb and if there is a problem it almost always means a bug report – Panther Apr 03 '15 at 15:34