Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backups #8947

Closed
GregorySchwartz opened this issue May 23, 2017 · 14 comments
Closed

Backups #8947

GregorySchwartz opened this issue May 23, 2017 · 14 comments
Labels
- Mailling list - Enhancement ☺ stale marked as a stale issue/pr (usually by a bot)

Comments

@GregorySchwartz
Copy link

GregorySchwartz commented May 23, 2017

I somehow had half of a document deleted and looked for the backups with autosave. However, there is a discrete difference in autosave verses backups. I was curious as to why there were no backups being generated and found #2271. I don't think this is a solution to the backups problem by disabling it completely -- I had to re-enable it and come up with my own configurations to save backups per session ~/.backups/per-session and per save ~/.backups/per-save. Can we have a nice interface for this in spacemacs?

Gathered from around the web, probably all from https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files#151946:

  ;; Backups
  (setq make-backup-files t)
  (setq version-control t     ;; Use version numbers for backups.
        kept-new-versions 10  ;; Number of newest versions to keep.
        kept-old-versions 0   ;; Number of oldest versions to keep.
        delete-old-versions t ;; Don't ask to delete excess backup versions.
        backup-by-copying t)  ;; Copy all files, don't rename them.
  (setq vc-make-backup-files t)
  ;; Default and per-save backups go here:
  (setq backup-directory-alist '(("" . "~/.backup/per-save")))

  (defun force-backup-of-buffer ()
    ;; Make a special "per session" backup at the first save of each
    ;; emacs session.
    (when (not buffer-backed-up)
      ;; Override the default parameters for per-session backups.
      (let ((backup-directory-alist '(("" . "~/.backup/per-session")))
            (kept-new-versions 3))
        (backup-buffer)))
    ;; Make a "per save" backup on each save.  The first save results in
    ;; both a per-session and a per-save backup, to keep the numbering
    ;; of per-save backups consistent.
    (let ((buffer-backed-up nil))
      (backup-buffer)))

  (add-hook 'before-save-hook  'force-backup-of-buffer)
@svenpanne
Copy link

As an Emacs user for decades who recently switched to spacemacs, I'm slightly confused: Why is the following in config.el at all?

;; don't create backup~ files
(setq make-backup-files nil)

#2271 mentions that there is a rationale for this, but what is it? What can I do to get the traditional way back, e.g. only 1 non-numbered backup living directly next to the original file? Googling around didn't show anything useful. Has setting back make-backup-files to t any negative effect?

Having at least one backup of the previous state is essential for an editor IMHO, not every file is under version control.

@jwnki
Copy link

jwnki commented Nov 12, 2017

I absolutely agree with @svenpanne Why use such a bad default at all? I just lost a file which I couldn't recover from auto-save, and was really upset with this no backup policy. Especially, since usually the defaults in spacemacs are set in a smart way.

@jeffmacdonald
Copy link

Here here. I'd love to know more context/history about this one.

@hyiltiz
Copy link

hyiltiz commented Oct 29, 2018

As #2271 pointed out, Spacemacs does save backups for local and remote edits under ~/.emacs.d/.cache/auto-save/site. Before you freak out, it may be practical to first check if your file still has a backup there.

@igor-kupczynski
Copy link
Contributor

igor-kupczynski commented Jan 27, 2019

As #2271 pointed out, Spacemacs does save backups for local and remote edits under ~/.emacs.d/.cache/auto-save/site. Before you freak out, it may be practical to first check if your file still has a backup there.

@hyiltiz these are not backups, but rather autosaves. See http://pragmaticemacs.com/emacs/auto-save-and-backup-every-save/ :

Emacs has two useful ways of protecting you from data loss. The first is auto save, which saves a copy of a file every so often while you are editing it. If some catastrophe caused you to close Emacs or shut down your machine without saving the file then you can use M-x recover-file to recover the file from its auto save.
(...)
The other way Emacs protects you is to make backups of your files. By default the backup file is made in the same directory as the original with a name like file~. The way the backup works is that Emacs makes a copy of a file the first time you save it in an Emacs session.

Spacemacs does auto saves, but not backups

@GregorySchwartz provided a nice descriptions on how backups could be configured in spacemacs and I've coded something like that in a layer #11903

@hyiltiz
Copy link

hyiltiz commented Feb 25, 2019

As mentioned in #2271, this line in the snipped above (setq make-backup-files t) is crucial it is not mentioned in StackOverflow, EmacsWiki or most others' setup on Emac's backup functionality as it was on by default in vanilla Emacs. Any other backup configurations will not kick in without it.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 28, 2020
@GregorySchwartz
Copy link
Author

I believe this feature is still very much needed.

@hyiltiz
Copy link

hyiltiz commented Mar 5, 2020

@GregorySchwartz could you propose what needs to be done by Spacemacs to resolve then close it?

@svenpanne
Copy link

@GregorySchwartz could you propose what needs to be done by Spacemacs to resolve then close it?

I think people (including me) simply want the traditional Emacs behavior back, i.e. keeping (perhaps numbered) backups of files which are not under version control. I think almost nobody understands in detail why this isn't the case with Spacemacs or how to fix that, because nobody really understands the rationale for disabling it. 🤔

@GregorySchwartz
Copy link
Author

@hyiltiz I currently use my solution in the original post, but it looks like @igor-kupczynski submitted a pull request for their own layer in #11903.

@duianto duianto removed the stale marked as a stale issue/pr (usually by a bot) label Mar 15, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Mar 15, 2021
@ColeWunderlich
Copy link

ColeWunderlich commented May 10, 2021

I believe this is valuable behaviour and do not understand why it is disabled. (I just spent a good 15 min trying to figure out why I couldn't find any backup files until I eventually found this issue).

If for some reason spacemacs is against creating backups in the local directory, they could be stored by default in a similar location to autosaves, ie ~/.emacs.d/.cache/backups

This could be enabled in the default config with something along the lines of:

(setq make-backup-files t)
(setq backup-directory-alist `(("." . "~/.emacs.d/.cache/backups")))

@github-actions github-actions bot removed the stale marked as a stale issue/pr (usually by a bot) label Oct 17, 2021
Copy link

github-actions bot commented May 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Mailling list - Enhancement ☺ stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests

9 participants