-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·44 lines (37 loc) · 1010 Bytes
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#set umask
umask 022
# Functions
command_exists() {
command -v $@ >/dev/null 2>&1
}
do_backup() {
echo "Backing up list of installed packages"
apt-mark showmanual > ~/_pkgs.list
echo "Backing up sources list"
sudo cp -R /etc/apt/sources.list* ~/
echo "Backing up repo keys"
sudo apt-key exportall > ~/_repo.keys
echo "Creating tarball"
sudo tar -czvf "/$(whoami).home.tar.gz" ~
echo -e "*****\nAll Done\n*****"
}
do_restore() {
echo "unpacking tarball"
tar -xzvf "/$(whoami).home.tar.gz"
echo "Restoring repo keys"
sudo apt-key add ~/_repo.keys
echo "Restoring sources list"
sudo cp -R ~/sources.list* /etc/apt/
echo "Installing packages"
sudo apt update
xargs sudo apt install -y < ~/_pkgs.list
echo "Don't forget to clean up\n$(ls -l ~/_repo.keys)\n$(ls -l ~/sources.list*)\n$(ls -l ~/_pkgs.list)"
}
main() {
case "$@" in
"backup") do_backup ;;
"restore") do_restore ;;
esac
}
main "$@"