blob: 1550e51c70f6de75dfecc6ba6accbed2ea690682 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# dots-backup
Bash script to back up dotfiles into a local git repo, and restore them on any system.
## Requirements
- `bash`
- `rsync`
- `git`
## How It Works
`dot-backup.sh` reads a list of dotfiles, copies them into a local git repo using `rsync`, then auto-commits any changes.
Backup layout:
```
~/Programming/GIT/my-dotfiles/
├── home/ # files from $HOME (relative paths)
│ ├── .bashrc
│ ├── .gitconfig
│ └── .config/
│ └── nvim/
└── system/ # files from / (absolute paths)
└── etc/
└── bash_completion.d/
```
## First Run
```bash
git clone https://github.com/you/dots-backup
cd dots-backup
./dot-backup.sh
```
On first run the script creates `~/Programming/GIT/my-dotfiles` and initializes a git repo inside it. Add a remote so you can push:
```bash
cd ~/Programming/GIT/my-dotfiles
git remote add origin git@github.com:you/my-dotfiles.git
git push -u origin master
```
## Usage
```
./dot-backup.sh [options]
-n, --dry-run Show what would be copied without copying
-v, --verbose Print each file as rsync transfers it
-r, --restore Restore dotfiles from backup to original locations
-q, --quiet Suppress stdout; write output to log instead
-h, --help Show this help
```
## Daily Routine
Run manually after changing config:
```bash
./dot-backup.sh
```
Or automate with cron (silent, logs to `~/.local/share/dot-backup/backup.log`):
```bash
# crontab -e
0 * * * * /path/to/dot-backup.sh -q
```
After backup, push manually:
```bash
cd ~/Programming/GIT/my-dotfiles && git push
```
## Restoring on a New Machine
Preview what would be restored first:
```bash
./dot-backup.sh -r --dry-run
```
Then restore:
```bash
./dot-backup.sh -r
```
System files (absolute paths like `/etc/bash_completion.d`) may need `sudo`.
## Configuration
Copy `config.example` to `~/.config/dot-backup/config` and edit:
```bash
mkdir -p ~/.config/dot-backup
cp config.example ~/.config/dot-backup/config
```
Available options:
```bash
DEFAULT_OUTPUT_DIR="${HOME}/Programming/GIT/my-dotfiles"
LOG_FILE="${HOME}/.local/share/dot-backup/backup.log"
DOTFILES_LIST="${HOME}/.config/dot-backup/files.list"
```
## Adding Files
**Edit the script** — add paths to the `DOTFILES` array in `dot-backup.sh`.
**Or use the external list** — add paths to `~/.config/dot-backup/files.list`, one per line:
```
# extra dotfiles
.config/myapp
.config/otherapp.conf
/etc/hosts
```
Relative paths are treated as `$HOME`-relative. Absolute paths (starting with `/`) are treated as system files.
|