Tuesday, December 6, 2016

Linux One-Liner Config Backup

So here at $newjob we've ran into Linux server, in all three environments, with huge uptimes and little documentation.  My co-workers already had one such beast get a forced reboot and things did not work correctly when it came back up.
So this morning I lucked into a nice one-liner that will pull all the infos.  Seriously it's damn good.  Props go out to /u/WOLF3D_exe


history >> "$HOSTNAME"_"$USER"_`date +%F`.log && last  -n 666 -a -d -x -F >> "$HOSTNAME"_"$USER"_`date +%F`.log && who >> "$HOSTNAME"_"$USER"_`date +%F`.log && uptime  >> "$HOSTNAME"_"$USER"_`date +%F`.log && uptime -p  >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /etc/redhat-release  >> "$HOSTNAME"_"$USER"_`date +%F`.log && uname -a >> "$HOSTNAME"_"$USER"_`date +%F`.log && iptables-save  >> "$HOSTNAME"_"$USER"_`date +%F`.log && netstat -tunap >> "$HOSTNAME"_"$USER"_`date +%F`.log && ps aufx >> "$HOSTNAME"_"$USER"_`date +%F`.log && yum list installed >>  "$HOSTNAME"_"$USER"_`date +%F`.log && chkconfig --list >> "$HOSTNAME"_"$USER"_`date +%F`.log  && chkconfig --list |grep on >> "$HOSTNAME"_"$USER"_`date +%F`.log  && >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /etc/passwd >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /etc/group >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /etc/ssh/ssh_config >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /etc/ssh/sshd_config >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /root/.ssh/config >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /root/.ssh/authorized_keys >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /root/.ssh/known_hosts >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /home/*/.ssh/config >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /home/*/.ssh/authorized_keys >> "$HOSTNAME"_"$USER"_`date +%F`.log && cat /home/*/.ssh/known_hosts >> "$HOSTNAME"_"$USER"_`date +%F`.log

No comments:

Post a Comment