sh backup_packages.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh backup_packages.sh相关的知识,希望对你有一定的参考价值。

#!/bin/bash

if [ ! `id -u` -eq 0 ]; then
  echo "Need to run as root"
  exit 1
fi

function get_timestamp() {
	numChar=5; # number of chars to take off end
	timeStamp=$(date +%Y%H%d.%N);
	endChar="$((${#timeStamp}-$numChar))";
	echo "$(echo $timeStamp | cut -c1-$endChar)";
}

DIR_BACKUP="/backup/$(get_timestamp)"
mkdir -p "$DIR_BACKUP"
cd "$DIR_BACKUP"


# Packages list
dpkg --get-selections > "packages.list"

# Repos list
mkdir "apt-sources"
cp -R /etc/apt/sources.list* "./apt-sources"

# Apt keys
apt-key exportall > "keys"

# Desktop apps
for app in $(ls /usr/share/applications); do
  echo "$app" >> usr-share-applications
done

# Local apps
if [ -d "$HOME/.local/share/applications" ]; then
  for app in $(ls "$HOME/.local/share/applications"); do
    echo "$app" >> "local-share-applications"
  done
fi

exit 0

以上是关于sh backup_packages.sh的主要内容,如果未能解决你的问题,请参考以下文章

Linux下执行.sh文件

如何使我的命令行在具有扩展名(.sh)和名称如“weird.sh.sh.sh”的文件上工作

sh sh_template.sh

sh sh.sh

Linux下面如何运行 SH文件

配置告警系统主脚本main.sh mon.sh load.sh 502.sh disk.sh