How can I archive the proc file system?

I would like to take a snapshot of my entire proc file system and save it in a tarball (or in the worst case, merge all the text files together into one text file).

But when I run:

tar -c /proc

I get segfault.

What is the best way to do this? Should I set up some sort of recursive walk through each file?

I have only basic nix utilities like bash, cat, ls, echo etc. I have nothing like python or perl or java.

+3
source share
3 answers

linux/proc , . , . , rm -rf /proc, .

/dev i-, . , , , . , , (2) . , , , .

, tar /proc segfault, , /proc : , , , , , (2) . , .

, tar /proc/kmsg, :

# strace cat /proc/kmsg
execve("/bin/cat", ["cat", "kmsg"],
open("kmsg", O_RDONLY|O_LARGEFILE)      = 3
// ok, no problem opening the file for reading
fstat64(3, { st_mode=S_IFREG|0400,  st_size=0,
// looks like a normal file of zero length
// but cat does not pay attention to st_size so it just
// does a blocking read
read(3, "<4>[103128.156051] ata2.00: qc t"..., 32768) = 461
write(1, "<4>[103128.156051] ata2.00: qc t"..., 461) = 461
// ...forever...
read(3, "<6>[103158.228444] ata2.00: conf"..., 32768) = 48
write(1, "<6>[103158.228444] ata2.00: conf"..., 48) = 48
+++ killed by SIGINT +++

/proc/kmsg - , 0 (EOF), , , ^ C.

, /proc/kmsg:

$ tar --version
tar (GNU tar) 1.22
# tar cf /tmp/junk.tar /proc/kmsg
$ tar tvf /tmp/junk.tar
-r-------- root/root         0 2010-09-01 14:41 proc/kmsg

strace, GNU tar 1.22 , st_length == 0 , .

, tar , 0, () , malloc (3), . tar /proc/kmsg, .

, /proc. ? . ? . ~ 1000 , /proc/<pid> psuedo , ? .

, , : /proc/sys/vm/lowmem _reserve_ratio, , - ?

+6

, , - , , . script, /proc /tmp/proc. gzipped. , (, , ..) , .

cd /
mkdir /tmp/proc
find /proc -type f | while read F ; do
   D=/tmp/$(dirname $F)
   test -d $D || mkdir -p $D
   test -f /tmp/$F || sudo cat $F > /tmp/$F
done

: , cat cp. cp -a /proc /proccopy , "kcore". mc (Midnight Commander) /proc, tar gzip, "Can not read file XYZ", "kcore" .

+2

:

ls -Rd /proc/* > proc.lst 
foreach item (<proc.lst>)
  echo "proc_file:$item"
  if (-f $item) cat $item
end

:

" ... ..."

(IMHO... ). , /proc/ * . "", :

The linux / proc file system is in fact kernel variables that claim to be the file system. Thus, nothing needs to be saved for backup. If the system allows you, you can rm -rf / proc, and it will magically appear on the next reboot.

... on the grounds that he does not answer the question, makes a false statement and contains free information that is not relevant to the question.

+1
source

Source: https://habr.com/ru/post/1762946/


All Articles