aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 1a5f0ed3f1910579e0385b81886fb618ce51fd45 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 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:

1. Creates `~/.config/dot-backup/` and `~/.local/share/dot-backup/` and prints a short setup summary
2. Creates `~/Programming/GIT/my-dotfiles/{home,system}` and initializes a git repo inside it
3. Runs the backup immediately using built-in defaults

Optionally set up a config file and custom files list (script will tell you the exact paths):

```bash
cp config.example ~/.config/dot-backup/config
touch ~/.config/dot-backup/files.list
```

Add a remote to the backup repo 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
  -p, --push       Push to remote after commit
  -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
```

Push manually after backup:

```bash
cd ~/Programming/GIT/my-dotfiles && git push
```

Or set `GIT_REMOTE` in config and use `-p` to push automatically:

```bash
./dot-backup.sh -p
# or combined with cron:
./dot-backup.sh -q -p
```

## 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
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"
GIT_REMOTE="git@github.com:you/my-dotfiles.git"
GIT_BRANCH="master"
```

`GIT_REMOTE` — if set, script ensures it is registered as `origin` on every run. Required for `--push`. `GIT_BRANCH` defaults to the current branch if unset.

## 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.